Identifiers in C Programming

Identifiers are the user defined terms or names in the code, mainly used to identify variables, structures,  function etc. They are not part of keywords and keywords cannot be used as identifiers. These are used to perform some operations in the code. It can also be considered as named memory location in the system. In order to perform any operation, we need to have memory allocated and these allocated memories are uniquely identified  by unique names called identifiers. For example :

int intVar1, intSum;
float flAvg;
function addNum();

Here int, float, function are all keywords and intVar1, intSum, flAvg, addNum are the identifiers. Keywords are used along with identifiers to define them. keywords define the functionality of the identifiers to the compiler.

These identifiers are composed of character sets. These character set consists of alphabets – both upper and lower case, digits from 0 to 9, white spaces, and special characters like &, %, $, #, (, ), *, ., ,, ;, -, _, !, |, {, }, ^, “, ‘, +, *, / etc. When we create an identifier, we need to use these character sets and follow certain rules to create them. We can give any name to the identifier with any length. However compiler considers first 31 characters and compares with other identifiers for 31 characters. Hence any two identifiers cannot have same name for its first 31 characters. However, it is always advisable to give meaningful names to the identifiers.

For example when we use two variables to add them, we may tend to name the variable name as ‘a’, ‘b’ and ‘c’. But from these names we are not clear which variables are used for adding and which variable stores the result. If we use the names as var1, var2 and sum, it is clear that first two variables are used for adding and sum is used for storing the result. But here we are not clear about what type of numbers are being added. Hence if we define the variable names as intVar1, intVar2 and intSum, we are clear that it is adding two integer variables resulting into integer sum. We can even specify the names as int_var1, int_var2 and int_sum, whichever is convenient but it should give complete meaning to the variables as well as the code.

Identifiers should always start with letter or underscore. It can never start with any space or special characters. When we create an identifier starting with underscore, care should be taken for not to have same name as system identifiers. If we create any identifier names same as system identifiers, then it will modifier system identifiers, which is dangerous.

Translate »