Data Element is a type of program element that can enable us to store data in memory.
In this lesson we are discussing about two such data elements that are variable and constant.
Variable is a memory location referring with an identifier whose value changes from time to time during program execution.
Declaration of Variables: Declaration associates a group of identifiers with a specific data type. We can understand declaration as an introduction of an identifier with its characteristics.
Example of Variable Declaration statements:
int a;
float r1,r2;
CONSTANT:
A constant is a memory location referred by an identifier whose value cannot be changed throughout the execution of a program.
Declaration of constant can be done with the following syntax:
const =’value’;
Again, the values that can be stored inside the memory location referring by a variable or constant also known as Constants.
Based on the four data types we have four types of constant values:
- Integer Constants Eg: 32727, 45, 8
- Floating Point Constants Eg: 2.58, 56.0
- Character Constants Eg: ‘A’, ‘c’, ‘u’
- String Constants Eg: “Rama”, “blue sea”, “ABC123”
Rules to form Integer and Floating Point Constants
- No comma or blank space is allowed in a constant.
- It can be preceded by – (minus) sign if desired.
- The value should lie within a minimum and maximum permissible range decided by the word size of the computer.
Symbolic Constant is a name associated with a sequence of characters or any basic type of constant. Symbolic constant is replaced with the constant at the time of compilation.
Symbolic Constants can be defined with the following preprocessor statement:
#define
Eg:
#define print printf
#define MAX 100
#define TRUE 1
#define FALSE 0
#define SIZE 10