variables in c programming

Variables in c language

Welcome to this article here we will discuss what is variables and rules for declaring variables in c.

Variables in c :

When we want to print something like the hello world program at that point we do not need any variables.

We just have to write printf and hello worldinside that printf .

But if you want to do some task such as you want to find out the maximum numbers among three numbers then you have to stores those numbers into a place or in computer memory.

To stores these numbers you need variable names and they have some addresses.

Now if you want to access these addresses then how you will access these addresses.

And it is not possble for us to remember those addresses .

So what we can do that we can provide the names of these addresses and now if you want to access these numbers you can easily access them by calling their names.

So these names known as vriables names or variables.

It is nothing but simply a name which consist of memory location.

We can also say that variables are the name which is use to stores the value of data.

We can change the variables value according to our needs.

Suppose in a program we assign a variable name and assign some values to that variable we can change that value later also.

If we define the variables then it would be like this -Variables can take different values but only one at a time.

We can change these values during the execution of a programme.

A datatype is associates with the each variable.

The data type of the variable decides what values it can take.

And the rulesfor naming variables are same as that for naming identifiers.

How to declare variables in the c program:

For the declaration, we need two things one is the datatype and another is the variable name.

We can write any types of datatype according to our requirements, some data types are- int, char, float, double, etc.

And after the datatype we have to write a name but which we can decide according to our convenience.

And at last we have to provide semi colon.

example :- int a ;

Here the example is telling the name of the memory location that is a, and when the compiler will compile these things during the execution of the program then the compiler tells that compiler to define a space.

Now if you want to stores some values here then you just have to write a=10, and 10 would be assigned to your memory location.

The first step is the declaration of our variables and the second step is the initialization of our variable.

We can also do the declaration and initialization in a single statement like this-

int a =10;

but if you first initialize the data and then declare the data then that is not correct, like this


int a; that is not a correct method at all because we have to first declare variables data and then initialize values into there.

We can use any kind of datatype such as float, here we can only stores float datatype such as –

float a;


if we use char ,then that will only stores character values such as

char a;

a=’a’;(here both the a are not the same one is character constant and another is variable that holds the character).

Now while constructing the name of the variables we should have to follow some rules:

well, a variable name may consist of letters, digits, and a special symbol that underscores.

so, if we write ABC then that is valid, if we write average then that is also valid if we write some then that is also easy and if we write sum123 then that is also the correct method, underscores are also allow by our compiler.

Now we will talk about the invalid cases, if we write some then give a space and then write 12 then that is not correct, some $12 then it is also not correct.

The second rule is that the variable names are also starts with letters -if we write the variable name starts with 12sum then it will not be consider as a correct variable.

Some compiler also allows us to started with the underscores like _sum, that is also correct.

Any quota, space is not allowed only underscored are allowed.

The next rule is that one cannot use any keywords while the declaration of variables.

Keywords are some special words and reserved words which we use for the execution of a program.

In c language, there are 32 reserved keywords and these have some predefined meaning. If, for, switch these are keywords so we cannot use these keywords when we are declaring any variables.

And we have to remember one more thing the compiler considered the uppercase and lowercase letters as different.

For example, if we write Sum, sum, SUM, then all are considered as different variable names by the compiler.

The syntax for declaring variables :

Data _type variable_name;

This is a very perfect symbol for declaring a variable, we have to first write a data type and give a small space and after that, we have to write our variable name, and to terminate that program at the end we have to provide a semi colon.

It is already mentioned that we can take any data type such as int, float, char, double besides that we can also check secondary data type also.

And remember one more thing that doesn’t create any variable with void data type because void is not used to create any data type it is always used to create functions.

Among these five fundamental data types, we can use only four datatypes. Because void actually means zero.

With the help of the int data type, we can create 2 bytes memory, the float is used to create 4 bytes memory, double is used to create 8 bytes memory, and void is used to store zero bytes.

We can declare multiple variables with only one datatype also. To do that first have to declare the data type and then the variables name.


int a,b,c;(here we create 3 variables with the name of a,b and c all the variables are int type

int a,b,c=5;(here we create 3 variables with the name of a,b, and c and assign 5 in the c variable).

Types of variables :

variables in c programming
variables in c programming

There are mainly three types of variables in c programme such as=

1.local variable variable

3.environment variable

Also read

Operators in c programming language
Unary operator in c language
Best youtube channel to learn c programming
Printf in c programming
Best editor for c programming


In this article, we discuss how you define variables in c programming language and various rules for declaring variables.

To read this kind of informational article please follow our website.