Keywords and Identifiers
In this article, you can learn about Keywords and Identifiers in the C programming language and the usage of these in your programs.
Keywords
Keywords in C are words that are preserved and have been described to the C compiler already. These are the pre-defined words and the meaning cannot be changed. And hence keywords cannot be used as variable names which will return an error.
In total there are 32 keywords in the C programming language.
auto | break | case | const | char |
---|---|---|---|---|
continue | default | do | double | else |
enum | extern | float | for | goto |
if | int | long | register | return |
short | signed | sizeof | static | struct |
switch | typedef | union | unsigned | volatile |
void | while |
Let us look into some of the keywords and their functions in C.
Break Break, when used inside a loop it brings the program control out of the loop or terminates the loop immediately.
Continue The continue statement in a loop ends the current iteration and forces the next iteration to take place bypassing any other statements inside.
Switch The switch keyword is used to perform a block of statements that is when you have to execute a different task for each choice.
Int Keyword int declares the datatype integer.
Char This keyword char declares a character variable.
If…else In C programming, the if and else are looping statements used in decision making.
Goto Goto is used when you have to transfer the program control to a particular label.
Return The keyword return terminates the function and returns a value.
Void Void means no value or null.
Identifiers
The names given to constants, variables, functions and user-define data are known as Identifiers. It is assigned by the user in the program.
There are a set of rules to frame an Identifier.
- An identifier can be of alphanumeric values only i.e letters and digits. (A-Z, a-z, 0-9)
- Underscore _ can be used in an identifier.
- Identifier names must be unique.
- Keywords cannot serve as an Identifier.
- No special character is allowed.
- The first character of an identifier must be an alphabet or underscore.
- Identifiers are case-sensitive.
- No white spaces are allowed.
Below is an example of an Identifier and keyword.
int Total;
float student_percent;
Here int and float are keywords, Total and student_percent are identifier.