Identifiers in c | Rules for constructing C identifier

  Identifiers in c

C identifiers are names given to variables, functions, arrays, structures, unions, and labels in C programming language. They are used to identify and access these entities in the program.

Identifiers in c

Rules for constructing C identifier

1. Identifiers can contain letters (both uppercase and lowercase), digits, and underscores.
2. The first character of an identifier must be a letter or an underscore.
3. Identifiers are case sensitive, meaning that uppercase and lowercase letters are treated differently.
4. Identifiers should not be a keyword or reserved word in C.
5. Identifiers can be of any length, but only the first 31 characters are significant.
6. Identifiers cannot contain spaces or special characters like !, @, #, $, %, ^, &, *, (, ), -, +, =, {, }, [, ], |, \, :, ;, ", ', <, >, ,, ., ?, /.

Example :

  1. total, sum, average, _m _, sum_1, etc.                                                                                                                                        

Example :

  1. 2sum (starts with a numerical digit)  
  2. int (reserved word)  
  3. char (reserved word)  
  4. m+n (special character, i.e., '+')  

Types of identifiers

a. Internal identifier

b. External identifier

Internal Identifier

If the identifier is not used in the external linkage, then it is known as an internal identifier. The internal identifiers can be local variables.

External Identifier

If the identifier is used in the external linkage, then it is known as an external identifier. The external identifiers can be function names, global variables.

Differences between Keyword and Identifier

KeywordIdentifier
Keyword is a pre-defined word.The identifier is a user-defined word
It must be written in a lowercase letter.It can be written in both lowercase and uppercase letters.
Its meaning is pre-defined in the c compiler.Its meaning is not defined in the c compiler.
It is a combination of alphabetical characters.It is a combination of alphanumeric characters.
It does not contain the underscore character.It can contain the underscore character.

 Example.

  1. int main()  
  2. {  
  3.     int a=10;  
  4.     int A=20;  
  5.     printf("Value of a is : %d",a);  
  6.     printf("\nValue of A is :%d",A);  
  7.     return 0;  
  8. }  

Output

Value of a is : 10
Value of A is :20  

The above output shows that the values of both the variables, 'a' and 'A' are different. Therefore, we conclude that the identifiers are case sensitive.

In summary, C identifiers are important names used to identify and access various entities in a C program. By following the simple rules for naming identifiers in C, programmers can ensure that their code is well-organized and easy to read and understand.

Post a Comment

0 Comments