Differentiate between the following: Constant and Variable
Advertisements
Question
Differentiate between the following:
Constant and Variable
Advertisements
Solution
|
Constant |
Variable |
|---|---|
|
1. A constant is a value that cannot be changed during the execution of a program. |
1. A variable is a named memory location whose value can be changed during the execution of a program. |
|
2. A constant is declared using the |
2. A variable is declared by specifying its data type and name. |
|
3. Once a constant is assigned a value, it cannot be reassigned. |
3. The value of a variable can be modified whenever required during program execution. |
|
4. Constants are used to store fixed values that remain unchanged throughout the program. |
4. Variables are used to store data values that may change during program execution. |
|
5. Example: |
5. Example: |
