A variable is a name that may be used to store a data value. Unlike constant, variables are changeable, we can change value of a variable during execution of a program. A programmer can choose a meaningful variable name. Example : average, height, age, total etc.
Rules to define variable name
- Variable name must be upto 8 characters.
- Variable name must not start with a digit.
- Variable name can consist of alphabets, digits and special symbols like underscore
_
. - Blank or spaces are not allowed in variable name.
- Keywords are not allowed as variable name.
Declaration of variable
Declaration of variables must be done before they are used in the program. Declaration does two things.
- It tells the compiler what the variable name is.
- It specifies what type of data the variable will hold.
#include<stdio.h> #include<conio.h> void main() { int a,b,sum; //variable declaraction a=10; b=20; sum=a+b; printf("Sum is %d",sum); getch();
No comments:
Post a Comment