- What is C?
- Examples of identifier
- Rules for naming identifiers in C
- Types of identifier
- Differentiate between Keywords and Identifier
- Examples of keywords
What is C ?
C as a language is a beginners choice for programming. It’s important to know the basics of any language before you jump into writing programs.
Talking about identifiers, identifiers are names given to entities such as variable, function, array, structure, union , label etc. An identifier starts with letters and can be followed by underscore , digits or symbols. The starting letter of an identifier must be an alphabet or underscore.
If an identifier is used in external linkage then it is termed as external identifier and if an identifier is not used in external linkage then it is termed as internal identifier.
In a precise way, identifier is a collection of alphanumeric characters that starts with either alphabet or underscore. There are 52 alphabetic characters ( including uppercase and lowercase), underscore character, ten digits ( from 0 to 9), representing an identifier.
Examples of identifier:
int amount;
double _bal7nb;
Here , ‘ amount’ and ‘ _bal7nb’ are identifiers.
Rules for naming identifiers in C
● The first letter of an identifier should be either alphabet or underscore.
● The alphabet can be either in uppercase or lowercase. ● The first identifier can not start with the digit.
● After the first letter identifier can have character, digit, underscore.
● Identifiers are case sensitive, uppercase and lowercase letters are distinct.
● Commas and blank space are invalid while naming an identifier. ● Maximum length of the identifier is 31 characters. ● Keywords can not be named as an identifier.
● Identifiers should be short, meaningful and easy to understand.
Examples of identifier:
arnaV, Sum_, _lifeHack;
Types of identifier
There are two types of identifier:
1. Internal Identifier
2. External Identifier
1. Internal identifier : Identifiers which are used as a local variable or are not used in external linkage are called internal identifiers.
2. External identifier: Identifiers which are used as a global variable or used for naming function or any other external linkage are called external identifiers.
Let’s differentiate between Keywords and Identifier
In a programming language, keywords are predefined, reserved words which have a specific meaning to the compiler. In short, keywords are part of syntax while writing a program and cannot be used while naming an identifier.
● Keywords are written in lowercase while identifiers can be written in either uppercase or lowercase.
● Meaning of keyword is predefined to the c compiler while in case of identifier the meaning is not pre – defined to the c compiler.
● Keywords are combinations of alphabetical characters whereas identifiers are collections of alphanumeric characters. ● Keywords can not contain underscore character while identifiers can have underscore character.
Examples of keywords:
auto , double, int, float, char, else, long, switch, case, do, for, static, while, loop, short, default, volatile etc.
Let’s test case sensitivity of identifiers with the help of a program.
int main ()
{
int h = 78;
int H = 43;
printf( “ Value stored in h is : %d”, h);
printf( “ \nValue stored in H is : %d”, H);
return 0;
}
Output of the following program will be :
Value stored in h is : 78
Value stored in H is : 43
The output shows that the identifier is case sensitive.
A professional course can always help you enhance your knowledge about C.