Home »
C programming language
Identifier or Variable Naming Conventions in C
Last Updated : February 06, 2026
In C programming language, all variables which are using in the program must be declared before their usage. Variable should declare in the declaration section of the function scope (it may be main or other user define function). Declaration section starts at the beginning of any function just after the opening curly brace.
Rules and Recommendations for Identifier/Variable Naming Conventions
Here are the rules and recommendations through the compilers for identifier/variable naming conventions, all rules must be followed while declaring an identifier/variable.
1. Valid Starting Characters for Identifiers
An identifier/variable name must be start with an alphabet or underscore (_) only, no other special characters, digits are allowed as first character of the identifier/variable name.
Valid examples:
product_name, age, _gender
2. No Spaces Allowed in Identifier Names
Any space cannot be used between two words of an identifier/variable; you can use underscore (_) instead of space.
Valid examples:
product_name, my_age, gross_salary
3. Using Camel Case for Multi-Word Identifiers
If there are two or more words in an identifier/variable - you can also use "camel case" style to declare a variable. In the "camel case" style – first character of first word is either a lowercase alphabet or underscore (_) and first character of second word is a uppercase alphabet.
Valid examples:
productName, empName, grossSalary, _MyAge
When a variable name starts with underscore, next alphabet may uppercase alphabet.
4. Allowed Characters in Identifiers
An identifier/variable may contain only characters, digits and underscores only. No other special characters are allowed, and we cannot use digit as first character of an identifier/variable name (as written in point 1).
Valid examples:
length1, length2, _City_1
5. Maximum Length of an Identifier
There are only 32 characters including digits, underscores are allowed in an identifier/variable name.
6. Meaningful and Descriptive Identifier Names
An identifier/variable name should be of short length, meaningful and descriptive (here, I wrote short length, a short length variable can be easily remembered). For example, if you want to declare a variable to store gross salary of an employee, you can use gross_salary, grossSalary, gSalary, emp_gross_salary, empGrossSalary. But I would recommend using gross_salary or emp_gross_salary as these variable names are meaningful and descriptive.
7. Uppercase Naming for Constants and Macros
All constants and macros should be in uppercase, (this is a suggestion only)
Valid examples:
const float PI=3.14f;
#define MAX_LENGTH=100;
8. Commenting and Describing Variables at Declaration
Description of each variable should be written with the declarations, so that other programmers or you (when, you see/change the code again) could understand the use of the variables. For this you should declare each variable in a separate line and write comment after the declaration.
Valid examples:
char empName[30]={0}; /*to store employee name*/
int empAge=0; /*to store employee age*/
float gross_salary=0.0f; /*to store gross salary*/
9. Proper Indentation and Alignment of Declarations
Maintain indentation while declaring/defining an identifier/variable, in the last point declared variables are not in a proper indentation, you should write like this:
Valid examples:
char empName[30] ={0}; /*to store employee name*/
int empAge =0; /*to store employee age*/
float gross_salary =0.0f; /*to store gross salary*/
10. Mandatory Initialization of Variables
Each variable should be initialized with a default/initial value, an uninitialized variable may dangerous to use further without assigning a value (as they can be initialized with any random/garbage value).
11. Prefer Initialization Over Assignment During Declaration
Use initialization instead of assignment while declaring a variable
An assignment has following form:
int number; /*to store an integer number*/
number=0;
An initialization has following form:
int number=0; /*to store an integer number*/
Initialization with variable declaration is better as it clears declaration and default/initial value.
Restrictions on Using Keywords and Scope Rules for Identifiers
- There are some words which are reserved in the compiler, we call them keywords. Any of the keywords like int, char, float, if, else, while, for, do, break etc cannot be used as an identifier/variable name.
- We cannot declare more than one variable with same name in a scope, but variables having same name can be declared in another scope.
- Global and Local variables name may have same name. [Read: How to access global variable in a function when local variables name are same.]
Advertisement
Advertisement