In this tutorial you will learn about variables, constants and keywords in C.
Variables in C
In a typical C program we have to do a lot of computation. Of course there will be storing of some data in different locations of memory in computer. These memory locations are identified by their address like 56234. Suppose if programmer wants to access the particular locations like 10 times in a program to store another value at that location.
So It will become a tedious job for a programmer if he have to memorise the numerical address name. So to make this job easy we use variables.
So variables are nothing but the name of the locations or addresses of memory which is given by programmer.
Constants in C
In the above picture (1st) we have stored the constant value 3 at x location. The name of that location is x. It’s a variable. We can also store another value at x location.
Here X = variable (location or memory address name)
3 = constant
Try to understand the second example yourself if you have any doubt, do comment below.
There are two type of Constants
- Primary constants
- Secondary constants (We will learn them later)
At this stage we will only discuss primary constants. Primary constants are of three types.
- Integer constants
- Real constants
- Character constants
Real Constant or Floating Point Constant
Types of Variables
So it is quite obvious types of variables is similar types of constants. Eg: int x= 1;
Rules for writing variable names
- A variable name may contain alphabets, numbers and underscores.
- No other special character (other than underscore) can be used for writing variable name.
- A variable name should start with either underscore or alphabets.
- No space is allowed while writing variables.
Keywords in C
A question which may arise in your mind that, how computer will know that its integer variable or character variable or anything else?
The simple answer is with the help of keywords. In one of the above example I have used “int” keyword. Eg: int x=1
In this example “int” is a keyword and it will tell the computer that “x” will be an integer variable and it will only store integer constant.
There are 32 keywords used in C language which are given below. We will discuss them in later tutorials.
|Keywords in C|
Watch below video tutorial to learn more about variables and keywords in C.