C programming variables declaration rules
What is variables ?
C program variables provide space to store data in memory cell and perform the task of c program according give instruction by programmer, Variable is container of different data types to store value in it. Which provide space to store value in C program and value are stored in variable by providing particular memory location, you can say that variables are name of the storage location to store value The Variables are used in all other language like C++, Java, Python and JavaScript etc.
There are certain rules to declare any variable, variables are declared according data types and initialized value to perform task but variables value can changed during program execution, Variables stored value changed time to time, suppose a, b, c ,d are defined as integer data type initialized with a=10, b=5, c=20, to perform addition task d=a+b+c; and d=35 further addition a+d, a=45 in a same c program now you can see first a variable hold value 10 and after that end of program value have changed a=45 see example below to understand the concept of variables in c programming language.
What is variables in c programming language
What is variables declaration ?
Example of variable declaration in c program
In C programming language programmer need to tell system what kind of data type is used in a c program so programmer define data type before using it, suppose you want to make program to add simple two number so you need to define data type that Int data type will be used in C program to addition program example int a, b;
C programming variables declaration rules
Programmer need follow variables declaration rules otherwise there will be no memory allocation to variables and there will not work in programs
Characters are allowed in variables declaration
First Character should be alphabet or underscore
No special Characters are allowed to declare any variable, only underscore allowed.
Blank space and comma are not allowed
Variable name can not be declared with reserved keywords
1 Capital Letters ( A – Z)
2 Small Letters ( a – z )
3 Underscore( _ )
4 Numbers ( 0 – 9)
Example of variable declaration in c program
#include <stdio.h>
int main()
{
int a=10, b=20, c=a+b; // variable declaration
printf(“addition of two numbers = %d”,c);
return 0;
}
Note
in above example a, b and c are variables date type integer
a and b variable are initialized with value 10 and 20
c store the sum of a and b
print the value 30 that mean c stored value 30