c++ variables
The Variable is the name of memory location that can used to stored values. it can take different values but take one value at a time.so these all values can change during execution of program. The datatype is associated with every variable and datatype decides what values the variables can accept or take. there are rules for naming variables are same as that for naming identifiers.
Declaration of variables
Here in the Declaration data type may int, float, char, double etc. its depend on your choice how value you want to store. some examples of declaration of variables are-
In this example x is variable of type,salary variable is of type, and grade variable is of type. The datatypecan written as and can written as.we can declare more then one variable in one statement example
x,salary, grade, a, s;
Initialization of variables
When a variable is declare it contain garbage value. if we want some value we should assign some initial value to the variable during the declaration. this is known initialization of variable. example-
x=9;
salary=1000.9;
grade=’a’;
a=89;
s=7;
|
Rules for Declaration of variables
1. The variable name should consist of only uppercase and lowercase letters, digits and underscore sign(_).
2. The first character should an alphabet or underscore.
3. The name should not keyword(Reserved words).
4. The C is a case-sensitive, so the uppercase and lowercase are consider different, example NOTE and note are different
global=18;
globalprint()
{
cout << global;
}
|