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

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

auto break case char const continue default do double enum extern else for float goto int if long register return signed short sizeof switch struct static typedef union unsigned volatile void while

Identifiers

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

  1. 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.
  2. While naming identifier first character should always be letter.
  3. Both uppercase and lowercase letters may be used and are they are recognized as differently. For example: COUNT and count are two different identifiers.
  4. Only underscore ( _ ) is allowed among special symbols and is treated as letter.
  5. Space and other symbols are not allowed and they are invalid.
  6. 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)