Identifiers in C Language – Rules, Types, Examples & More
Basics of SQL
12 Hrs. duration
12 Modules
2600+ Learners
Start Learning
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.
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.
#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);
}
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.
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.
FAQs
Can identifiers be the same as C keywords?
No, Identifiers cannot be the same as C keywords. Keywords have predefined meanings in C and are reserved by the language.
Can identifiers in C start with a digit?
No, C-identifiers cannot start with a digit. They must begin with a letter or an underscore. Subsequent characters can include digits.
Are identifiers case-sensitive in C
Yes, Identifiers are case-sensitive in C. This means variable, Variable, and VARIABLE are considered different identifiers.
Can identifiers include whitespace characters?
No, identifiers cannot include whitespace characters . Whitespace is not allowed in identifiers and will result in a syntax error. Identifiers must be a continuous sequence of letters, digits or underscores.
Can identifiers be used as labels in switch statements?
Yes, identifiers can be used as labels in switch statements.
Hero Vired is a leading LearnTech company dedicated to offering cutting-edge programs in collaboration with top-tier global institutions. As part of the esteemed Hero Group, we are committed to revolutionizing the skill development landscape in India. Our programs, delivered by industry experts, are designed to empower professionals and students with the skills they need to thrive in today’s competitive job market.