Identifiers Tutorials
Programming
Identifiers in C
An identifier is a user-defined name used to identify variables, functions, arrays, structures, and other program elements in C.
In simple terms, identifiers are the names given by programmers to different components of a program.
Examples
Variable Identifier / Function Identifier
int age = 25;
void display() {
}Here, age is an identifier.
Here, display is an identifier.
Rules for Naming Identifiers
A valid identifier in C must follow these rules:
Can contain letters (
A-Z,a-z), digits (0-9), and underscore (_).Must begin with a letter or underscore.
Cannot start with a digit.
Identifiers are case-sensitive.
Cannot use C keywords as identifiers.
Special characters such as
@,#,$,%,-are not allowed.
Valid Identifiers
age
studentName
_count
totalMarks
student1Invalid Identifiers
1student
user-name
user@name
return
intExample: Identifier as a Variable
#include <stdio.h>
int main() {
int marks;
marks = 90;
printf("%d", marks);
return 0;
}Output
90In this example, marks is the identifier.
Example: Identifier as a Function
#include <stdio.h>
int sum(int a, int b) {
return a + b;
}
int main() {
printf("%d", sum(10, 20));
return 0;
}Output
30In this example, sum is the identifier.
Naming Conventions
Although not mandatory, these conventions improve code readability.
Variables
Use camelCase naming.
int studentAge;
int totalMarks;
int employeeCount;Constants
Use UPPER_SNAKE_CASE naming.
#define MAX_SIZE 100
#define PI 3.14Functions
Use camelCase and meaningful action names.
getName();
calculateSalary();
countFrequency();Structures
Use PascalCase naming.
struct Student;
struct Employee;
struct Car;Using Keywords as Identifiers
Keywords are reserved words in C and cannot be used as identifiers.
Incorrect Example
#include <stdio.h>
int main() {
int const = 90;
return 0;
}Error
error: expected identifier or '(' before '=' tokenThe error occurs because const is a C keyword and cannot be used as an identifier.
Common C Keywords
int
char
float
double
if
else
for
while
switch
case
break
continue
return
const
voidKey Points
An identifier is a user-defined name.
Used for variables, functions, arrays, structures, and other program elements.
Must start with a letter or underscore.
Cannot start with a digit.
Cannot be a keyword.
Identifiers are case-sensitive.
Meaningful names make code easier to read and maintain.