Variables and Keywords in C

In this blog you will learn about the variables and keywords in C. The previous blog was about the standard of the C language, which you can find here.


Just like the building blocks of any language are its words, the building blocks of a programming language are variables and keywords. Using variables and keywords, one can create an instruction, and using a set of instructions, one can create a program. So lets study these variables and keywords.


A variable is the name given to a memory location, and it is used to store data. Alternatively, an entity whose value may change during execution of a program is called a variable. Variables can have various data types, which determine the amount of memory that is allotted to that variable, and the operations that can be performed on that variable. Some of the data types available in C language are char, int, float, double, etc. We will explore these data types in detail later on.


There are certain rules that must be followed while naming a variable. If not, the compiler will generate an error.

  1. The length of the name of a variable must be between 1 to 31. The variable name must be a combination of alphabets, digits, or underscores.

  2. The first character of a variable name should be an alphabet or an underscore.

  3. Commas and blanks are not allowed in a variable name.

  4. No special symbol other than an underscore are allowed in a variable name.


According to these rules, some valid variable names are: x, emp_id, _date, num3.

Similarly, the following variable names would be considered invalid: 6, roll no, 2row, marks&.


A variable can be declared as: data_type var_name. Examples of declaration statements:

int a;

float avg_marks;

char s;


There are many types of variables in the C language. The main types of variables are as follows:


  1. Local Variable - A variable that is declared inside a function is called a local variable. The scope of a local variable is the function or block of code inside which it is declared.

  2. Global Variable - A variable that is declared outside the function is called a global variable. The scope of a global variable is the entire program, that means that any function can access a global variable.

  3. Static Variable - A variable that exists for the lifetime of a program is called a static variable. It’s value does not change during the execution of the program. A variable can be made static by adding the keyword ‘static’ in the variable declaration.


Keywords are predefined, reserved words in C which convey special meaning to the compiler. Every keyword is associated with a specific feature. There are 32 keywords in C language, and they are given in the table below.


auto double int struct

break else long switch

case enum register typedef

char extern return union

const float short unsigned

continue for signed void

default goto sizeof volatile

do if static while

You will learn the meaning and functions of these keywords as you continue studying the C programming language.

Happy coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor


Please leave comments if you find any inconsistency in the blog.

Follow Programmers Door for more.

#blog #c #learn #coding #programming


7 views

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door