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
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'st | Invalid (First character must be letter ) |
first | Valid |
total_area | Valid |
phone-no | Invalid ( ‘-‘ not allowed ) |
national flag | Invalid ( blank space not allowed ) |
f1car | Valid |
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
auto | break | case | char | const | continue | default |
do | double | else | enum | extern | float | for |
goto | if | int | long | register | return | short |
signed | sizeof | static | struct | switch | typedef | union |
unsigned | void | volatile | while |
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:
Post a Comment