ποΈ Introduction
Hello everyone!
In this lesson, we will understand the Rules for Naming Variables in C Language.
In programming, variable names are not chosen randomly. C language follows specific rules for naming variables. If we do not follow these rules, the compiler will generate errors and the program...Read More
πΉ Rule 1: A Variable Name Must Start with a Letter or Underscore
In C, a variable name must begin with:
An alphabet (AβZ or aβz)
OR
An underscore (_)
For example:
age
total
_value
These are valid variable names.
However, a variable name cannot start with...Read More
πΉ Rule 2: Variable Names Cannot Start with a Digit
Although numbers can be used inside a variable name, they cannot be placed at the beginning.
For example:
marks1 β
student2 β
total2025 β
But:
2025total β
This rule ensures clarity and avoids confusion...Read More
πΉ Rule 3: No Special Symbols Allowed
Variable names cannot contain special characters such as:
@
%
&
$
!
For example:
total@marks β
price#1 β
Only letters, digits, and underscore are...Read More
πΉ Rule 4: No Spaces in Variable Names
Variable names cannot contain spaces.
For example:
total marks β
student name β
If you need separation between words, you can...Read More
πΉ Rule 5: Variable Names Cannot Be Keywords
C has reserved keywords like:
int
float
return
if
while
char
These words already have predefined meanings in C.
You cannot use them as variable names...Read More
πΉ Rule 6: Variable Names Are Case-Sensitive
C is case-sensitive.
This means:
age
Age
AGE
All three are different variables.
So programmers must be careful while naming...Read More
πΉ Rule 7: Meaningful Variable Names Should Be Used
Although not a strict rule of the compiler, it is a good programming practice to use meaningful names.
Instead of:
x
a
b
Use:
totalMarks
studentAge
accountBalance
Meaningful names make programs easier to read...Read More
πΉ Rule 8: Length of Variable Name
C allows long variable names, but it is recommended to keep them reasonable and meaningful.
Very long names make code harder to read.
For example:
totalAmountOfStudentsInClass β (but too long)...Read More
π Quick Summary of Rules
Letβs quickly revise:
Must start with a letter or underscore.
Cannot start with a number.
No special characters allowed...Read More
Top comments (0)