In: Computer Science
C++ programming homework
What does it mean to declare a variable? Give an example.
What does it mean to assign a value to a variable? Give an example.
What is the different between assigning and initializing? Give examples.
1) Variable declaration
In c++ it is necessary to declare a varibale before using it.
When we declare variable it reserves memory for varible to store
value.
Syntax
datatype variablename;
Example
int number;
In this example we created a variable of 'int' datatype
and name of that variable is 'number'.
*****************************************************************
2) Assignment of variable
After declaring variable we can assign the value to that
variable.
In the process of variable assignment we store a value in that
variable
but in different statement than declaration statement.
Syntax
variablename = value;
Example
number = 100;
In this example we stored 100 into variable 'number'.
*********************************************************
3) Initialization of variable
Initialization of variable means we assign value to the
variable
at the time of variable declaration itself.
Syntax
datatype variablename = value;
Example
int number = 100;
In this example we declared a 'int' type variable 'number'
and also assigned 100 to it.