Tuesday, January 5, 2016

Character Sets Supported by C Programs

C uses alphabets (upper case 'A' to 'Z' or lower case 'a' to 'z'), digits ('0' to '9') and some certain special characters shown in the figure below to construct basic elements of C program (constants, variables, expressions, operators etc.)
C Character Set
C Character Set

Identifiers and Keywords

Identifiers are the names by which we can distinguish different program elements (such as variables, constants, functions). The identifiers consist of letters (uppercase or lowercase) and digits in any possible combination as long as it follows one rule of identifiers.


The rule states that every identifier must have a letter as its first character; no digits are allowed in the first character. So, while “first” is a valid identifier, “1st” is not. Also, no identifier must contain any special character except “_” (underscore). Given below, a list of examples of valid and invalid identifiers with a reason why they are invalid.

1'stInvalid (First character must be letter )
firstValid
total_areaValid
phone-noInvalid ( ‘-‘ not allowed )
national flagInvalid ( blank space not allowed )
f1carValid

There is another restriction for identifiers. Some reserved words can't be used as identifiers. These reserved words are predefined by C language and have predefined meanings and can be used for their intended purposes. They are called keywords. The list of keywords is given below

autobreakcasecharconstcontinuedefault
dodoubleelseenumexternfloatfor
gotoifintlongregisterreturnshort
signedsizeofstaticstructswitchtypedefunion
unsignedvoidvolatilewhile

C Keywords
All keywords are lowercase. So if you have an urge to use these keywords as variables, you can change any letter in the keywords to its uppercase character. But not using them as variable name is considered better programming practice.

No comments: