Keywords and Identifiers in C programming language

Keywords are the words whose meanings are already been defined by the compiler and we use them in our code to perform some special functions as per the definition in the compiler(like if, else etc). Keywords are also known as ‘Reserved Words’.

Identifier, also known as ‘Variable’, is an entity that can change its value during the execution of the program according to the programmer’s choice. These are used when we have to declare a contianer for a changing value and for fixed values we use Constants.

1. Keywords in C

Keywords when used in our code send a specific meaning to the compiler according to which the compiler judges the code and goes into further execution. Since Keywords are quite special to the compiler these words cannot be used as variable names, function names or as a constant. There are 32 keywords available in C.

Here’s a list of keywords available in C:


Compiler vendors like Borland, Microsoft, etc. also come with their own keywords excluding the ones above. According to the ANSI committee, these keywords must have two underscores before them. eg: __asm. Some other examples of these keywords are near, far, etc.

2. Identifiers in C

Identifiers or variables are used extensively in our programs and various scenarios like the numbers we enter, the result of calculations and also other such data are stored in these identifiers.

Data is saved in memory locations and Variables are named memory locations which make it easier to access the data and manipulate them.

The values in these memory locations can be overwritten anytime during the course of the program. Let us consider a variable

Let us consider a variable which has a specific memory location. At the beginning of the program, the user-defined its value as 8. In case the user needs to change its value at the mid of the program to perform certain calculations, to say 3, he can easily overwrite the value and make x=3. Since the value of these tokens varies during the program, they are known as variables.

Variables or Identifiers have a specific type. A variable declared as an integer can only store integer values, a variable defined as char can only have character as the data and likewise. But to declare a variable in C, there are certain rules. Let’s have a look at these rules:

  • A variable can be any combination of digits, alphabets(lowercase or uppercase or both) and underscore(_) whose length can be anywhere between 1 to 31. Some compilers allow 247 characters but using fewer characters would be convenient.
  • The first character in a variable cannot be a digit. It has to be either an alphabet or underscore(_).
  • A variable name cannot have commas or blank spaces.
  • Special characters other than underscore are not to be used in the variable name.

3. Declaring a variable in C

There are certain things that one should know about variable declaration:

  • Variables should be declared before its use.
  • Initializing a variable means assigning the variable a value.
  • Memory allocation of variables is done after defining the variable.

3.1. Syntax of Variable Declaration:

  • The syntax for the declaration of any variable is:
    datatype variableName;
    Eg: int x; char ch;
  • We can declare multiple variables of same types in a single statement-
    Eg: int x, y, z;
  • In case we need to initialize the variable with a value we follow the given syntax:
    datatype variableName=value;
    Eg: int x=5; char ch=’C’;
  • Initializing multiple variables of the same type in a single statement-
    Eg: int x=10, y=20, z=30;

4. Types of Variables in C

There are three types of Variables in C categorized according to their scope in the program. They are as follows:

  • Local Variable: The local variables are declared within a code block( like a function, switch block, if block, else block etc.) and are accessible within that block only not outside the block.
  • Global Variable: The global variables are declared outside the main function and are accessible throughout the program. These variables cannot be accessed in some other program.
  • Environment Variable: The Environment variables are accessible to all of the C programs and applications. They need not be declared or initialized. They can be accessed by inbuilt functions like getenv(), setenv(), putenv().

Helpful Links

Please follow C Programming tutorials or the menu in the sidebar for the complete tutorial series.

Also for the example C programs please refer to C Programming Examples.

All examples are hosted on Github.

Recommended Books

An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding

Do not forget to share and Subscribe.

Happy coding!! ?

Recommended -

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x