A constant is the name given to a memory location that store a fix value. These are defined using the keyword constant at the time of declaration statement. The constant are those whose value does not change during the execution of the program. The main difference between variable and constant is as given below:


1. Initialization of the variable at the time of declaration is optional but in case of constant it must be done at the time of declaration or immediately after it.
2. In case of a variable the value can be changed during the execution of the program but the value of a constant can not be changed during the execution of the program.

Note: C++ may allow declaration of any variable anywhere in the whole program but it must be before its first use in the program.

Syntax for declaration of a C++ variable in a program:


1. data_type  Variable_name;
2. data_type variable1, variable2,......., variablen;
3. data_type  Variable_name = Value_stored;
4. storage_class data_type  Variable_name;

Syntax for declaration of a C++ constant in a program:

1. variable = constant;
2. variable = expression;
3. data_type  Variable_name = constant;
4. # define symbolic_name = symbolic_constant;




Thanks
Mukesh Rajput

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: