C Program Tutorial For Beginners - Character, Identifiers, Keywords and Datatypes | Coding classpoint

Character set 



A character denotes any alphabet, digit or special symbol used to represent information. Valid alphabets, numbers and special symbols allowed in C are The alphabets, numbers and special symbols when properly combined form constants, variables and keywords.


Identifiers 

Identifiers are user defined word used to name of entities like variables, arrays, functions, structures etc. Rules for naming identifiers are: 
  • 1) name should only consists of alphabets (both upper and lower case), digits and underscore (_) sign. 
  • 2) first characters should be alphabet or underscore 
  • 3) name should not be a keyword 
  • 4) since C is a case sensitive, the upper case and lower case considered differently, for example code, Code, CODE etc. are different identifiers. 
  •  5) identifiers are generally given in some meaningful name such as value, net_salary, age, data etc. An identifier name may be long, some implementation recognizes only first eight characters, most recognize 31 characters. ANSI standard compiler recognize 31 characters. Some invalid identifiers are 5cb, int, res#, avg no etc.

Keywords

There are certain words reserved for doing specific task, these words are known as reserved word or keywords. These words are predefined and always written in lower case or small letter. These keywords cann’t be used as a variable name as it assigned with fixed meaning. Some examples are int, short, signed, unsigned, default, volatile, float, long, double, break, continue, typedef, static, do, for, union, return, while, do, extern, register, enum, case, goto, struct, char, auto, const etc.

Data types 

Data types refer to an extensive system used for declaring variables or functions of different types before its use. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The value of a variable can be changed any time. 

C has the following 4 types of data types 

basic built-in data types: int, float, double, char 

Enumeration data type: enum 

Derived data type: pointer, array, structure, union 

Void data type: void A variable declared to be of type int can be used to contain integral values only—that is, values that do not contain decimal places. 

A variable declared to be of type float can be used for storing floating- point numbers (values containing decimal places). The double type is the same as type float, only with roughly twice the precision. The char data type can be used to store a single character, such as the letter a, the digit character 6, or a semicolon similarly A variable declared char can only store character type value.

There are two types of type qualifier in c 

Size qualifier: short, long 

Sign qualifier: signed, unsigned

When the qualifier unsigned is used the number is always positive, and when signed is used number may be positive or negative. If the sign qualifier is not mentioned, then by default sign qualifier is assumed. The range of values for signed data types is less than that of unsigned data type. Because in signed type, the left most bit is used to represent sign, while in unsigned type this bit is also used to represent the value. The size and range of the different data types on a 16 bit machine is given below:


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.