Variables in C

In this article, I am going to tell what is a variable? what variable contains? how we can declare and initialize it?

 
Before starting variables in C language. Come to my question of whether the concept of variable is the same in every language? yes, of course, if you learn about variables in C it is applicable to every language like c++, java, python, etc..

Let's come to my question what exactly a Variable is? you can assume a Variable is a container where we store the data. Suppose you are having the small box which contains pens or stationary.here you can assume small box as a variable and data as a stationary or pen. I think you have understood the meaning of variable, if you do not understand don't worry, you can comment below, I will help. Let's move future depth in Variable Concept when you create a Variable, I mean when you are storing some data into a container, there is some memory is allocated for that variable in ram. Let's look at the syntax of a variable in c

//Syntax for declaration of Variable in C
  int a;

In the above example, variable "a" is declared.lets look at the syntax, " int " is a written to declare what type of data can be stored in "a". whereas "a" is the name given to the variable. from the above statement, we can conclude that variable "a" can store "int" type of data.
Now let's move to initialization of a variable


//Syntax for initialization of a variable
  a=10;

 we have declared variable "a" has int type. now we must store integer data into a variable. The above statement tells variable "a" stores value "10" of an integer data type. Every end of the statement you must end with a semicolon, so the compiler will understand statement has been finished.we can declare and initialize in a single statement, now look at the following code snippet


//Syntax for declaration and initialization of a variable in C
  int a=10;

Post a comment

0 Comments