Identifiers For C – The Most Detailed

This guide will teach you about C identifiers. In C, an identifier is a unique name that is used to identify a variable, array, function, structure, and so on. In the int num =10; declaration, for example, the name “num” is an identifier for this int type variable.
The identifier must be unique in order to identify an entity during program execution.

C identification rules

As the identifier is chosen by the programmer, certain rules are in place to remind the programmer and prevent the program from being executed until these rules are met.
1. Lowercase letters, uppercase letters, alphabets, underscores, and/or digits can all be used in an identifier. For instance, num 2, num8, bigNum, and so on are all valid identifiers.
2. A digit cannot be the first character of an identifier. 99number and 9number, for example, are invalid identifiers.
3. An underscore cannot be used to begin an identifier. Invalid identifiers include _num and _char.
4. Commas and whitespaces are not permitted in an identifier. In C, for example, “num 2” and “num, 2” are not permitted.
5. An identifier should not be longer than 31 characters.
6. Keywords and reserved words are not usable as identifiers. Declaring a variable name with “int” or “for” is not permitted in C because these are keywords.
Although this is not a rule, as a good C programming practice, you should always use meaningful, short, and readable identifiers.

Example of a C identifier

#include <stdio.h>
int main()
  int num=100;
  int Num=150;
  char ch = 'K';
  double bigNumberWithDecimalPoints = 122343434.83823;
  printf("Value of num is: %d",num);
  printf("\nValue of Num is:%d",Num);
  printf("\nValue of ch is: %c",ch);
  printf("\nValue of double is: %lf",bigNumberWithDecimalPoints);
  return 0;

Output: As you can see, the identifiers “num” and “Num” represent different variables with different values, indicating that the identifiers are case sensitive.

The distinction between a keyword and an identifier

The C language has pre-defined keywords that cannot be changed. The identifier is defined by the user and can be changed by the programmer.
C keywords are always lowercase. Identifiers can be in lowercase, uppercase, or both, depending on how the programmer defines them.
The C compiler can easily identify keywords because the compiler is already aware of their functionality. The programmer declares and uses identifiers, and their functionality is also defined by the programmer.
Underscores are not permitted in keywords. Identifiers can contain underscores but cannot begin with them.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button