Identifiers are a fundamental concept in the C programming language. They serve as a fundamental element in the program, including variables, functions, and other entities. Identifiers must start with the alphabet or underscore. This article explains the identifiers in the C language and their usage and rules.
What are Identifiers?
Identifiers are names in a programming language that define the identified variables, functions, arrays, or other user-defined items. They allow programmers or developers to access and manipulate them, and they must adhere to specific naming conventions and rules. In simple words, identifiers allow you to reference and manipulate these entities throughout your source code. For instance, when you declare a variable like int age, age is an identifier in the C programming language.
The following program demonstrates the Identifiers in C language:
Program
#include <stdio.h>
float calculate_area(float radius) {
const float PI = 3.14159;
float area = PI * (radius * radius);
return area;
}
int main() {
float radius = 5.0;
float area = calculate_area(radius);
printf("The area of the circle with a radius of %.2f is %.2f.\n", radius, area);
return 0;
}
Output
The area of the circle with a radius of 5.00 is 78.54.
Also Read: Control Statements in C

POSTGRADUATE PROGRAM IN
Multi Cloud Architecture & DevOps
Master cloud architecture, DevOps practices, and automation to build scalable, resilient systems.
Rules for Naming Identifiers in C
The C Developer must follow some rules before defining the Identifiers:
- We cannot use any keyword as an identifier in C language.
- All identifiers should have a unique name in the scope.
- Identifiers can not start with a digit.
- The identifier’s first character should always start with an alphabet or underscore, and then it can be followed by any character, digit, or underscore.
- Special characters are not allowed within an identifier.
- The identifier length should not exceed 31 characters.
Example of Identifiers in C
Program 1
#include <stdio.h>
int globalVar = 10;
void exampleFunction();
void First() {
int localVar = 20;
static int staticVar = 30;
register int regVar = 40;
printf("Inside exampleFunction:\n");
printf("localVar (local variable) = %d\n", localVar);
printf("staticVar (static variable) = %d\n", staticVar);
printf("regVar (register variable) = %d\n", regVar);
staticVar++;
}
int main() {
int mainVar = 50;
printf("Inside main:\n");
printf("globalVar (global variable) = %d\n", globalVar);
printf("mainVar (local variable) = %d\n", mainVar);
First();
First() ;
int _number = 60;
return 0;
}
Output
Inside main:
globalVar (global variable) = 10
mainVar (local variable) = 50
Inside exampleFunction:
localVar (local variable) = 20
staticVar (static variable) = 30
regVar (register variable) = 40
Inside exampleFunction:
localVar (local variable) = 20
staticVar (static variable) = 31
regVar (register variable) = 40
Program 2
#include <stdio.h>
struct _student {
int id;
int class;
char section;
};
void isEven(int num)
{
if(num%2==0){
printf("It is an Even Number");
}
else{
printf("It is not an Even Number");
}
}
void main() {
int studentAge = 20;
double Marks = 349.50;
isEven(453);
}Output
It is not an Even NumberValid Identifiers in C
Let’s see the valid identifiers in C language that follow every rule of the naming convention of identifiers we have already discussed in the above section.
Example of Valid C Identifier:
- Length: This identifier is valid because it contains only lowercase letters.
- Total_sum: This contains only ‘_’ as a special character
- _size: It starts with an underscore ‘_’ *len_ contains lowercase alphabets and an underscore.
- Rajkumar1 : This identifier is also valid because it followed the rules.
Also Read: Quick Sort in C
Invalid Identifiers in C
Let’s see the invalid identifiers in C language that do not follow every single rule of the naming convention of identifiers.
Example of Invalid C Identifier:
- 5num : It begin with a digit
- \@hello: It starts with a special character other than _
- int : It is a predefined keyword
- r n : It contains the blank space between the alphabet
- M+n: It contains the special character

82.9%
of professionals don't believe their degree can help them get ahead at work.
Difference between Keyword and Identifier
The difference between keywords and identifiers is fundamental in programming, particularly in languages like C.
| Keyword | Identifier |
| This is the reserved keyword, which is predefined by the language, used to perform specific functions or represent specific constructs | The programmer creates the name to identify the variable function in the program. |
| To define the syntax and structure of the programming languages | To label and access program elements |
| This cannot be changed or redefined because the compiler already defines it | They are user-defined and can be anything the programmer chooses within naming rules. |
| It is used directly by the language to perform operations (e.g., if, while, and int). | The programmer uses it to name elements like variables, functions and objects |
| int, return, class, public, if | myVariable, calculate, UserProfile |
Also Read: strcmp Function in C
Conclusion
In this article, we learned about the C language’s identifiers. Identifiers are essential for naming and acting on program elements, such as variables, functions, and arrays. Identifiers follow some specific rules, including starting with a letter or underscore and being followed by letters, digits, or underscores. By Understanding Identifiers, developers can enhance the readability and maintainability of source code.
Can identifiers be the same as C keywords?
Can identifiers in C start with a digit?
Are identifiers case-sensitive in C
Can identifiers include whitespace characters?
Can identifiers be used as labels in switch statements?
Updated on September 19, 2024
