What are the difference between variables and Constants in C++ language?

A variable is a place to store a piece of information or data in the computer memory's which is further retrieved to use in any processing in the program. Every variable in  computer program can be identified with the help of a variable name. The data stored in a variable cannot be static and can be changed during run time because it can not have a fixed value. But in case of a Constant, the value of it is fixed and cannot be changed during execution of the program.Its value is always fixed. 



Below, we have discussed some important point of difference between variables and constants:

1. Definition: Information in a variable is not static but information in a constant is static. It means that information in a variable can be changed during run time. But the information of constant can not be changed during run time.

2. Storage: Variable give the memory location for the storage of constant. Constant are the values stored in the variable. i.e char, string, number etc.   

3. Classification: Variable have not classification, its is simply a variable. Constant can be further classified as int , float. char, etc.

4. Rules: Variables does not accept special character rather then "_" and  "$". But constant accepts special characters.

5. Declaration: Int x=20, y=30 where x and y are variables, declared as integer types. whereas 20 and 30 as declared are constant in x and y.


6. Examples: z = 13 * x + 45 * y+20, here z, x and y are variables and 13, 45 and 20 are constants. 





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: