What are keywords and Identifiers in C?
Keywords and Identifiers are basic building block of C programs. In this article we will discuss about Keywords and Identifiers in detail.
Keywords are those words in C programming language whose meaning is already known to the compiler.
Keywords have standard predefined meaning. Keywords are also known as reserved words and we cannot alter the meaning of keywords.
Keywords are basic building block for developing C programs. There are only 32 keywords in standard C and these keywords must be written in lowercase.
C 32 Keywords
In C programming, name given to variables, constants, functions, arrays and various other user defined items are known as identifiers.
It can also be defined as a set of combinations of one or more letters or digits used to define constants, variables, functions etc.
Identifiers are defined by user and user should try to give meaningful name while using identifiers to increase the readability of program.
Rules for Creating Valid Identifiers
- In ANSI standard 31 characters long identifier are allowed. (But some implementation of C only recognizes 8 characters). It would be better to follow the rule of 8 characters.
- While naming identifier first character should always be letter.
- Both uppercase and lowercase letters may be used and are they are recognized as differently. For example: COUNT and count are two different identifiers.
- Only underscore ( _ ) is allowed among special symbols and is treated as letter.
- Space and other symbols are not allowed and they are invalid.
- Meaninful name should be given based on context.
Examples of Valid Identifiers
area test1 my_count fx for1
Examples of Invalid Identifiers
a rea (space can not be used) 1test (must start from letter) my-count (hyphen is not allowed) f(x) (parantheses are not allowed) for (keyword can not be used as an identifier)