Elementary Data Type: Variables And Constants:


A data object with a name that is bound to a value (or values) permanently during its lifetime. The constant value can only be a number, string or identifier which denotes constant.

A constant definition in Pascal introduces an identifier as a synonym for the constant value.

Pascal uses the reserved word const to begin a constant declaration.

const PI=3.1415;

In ALGOL68 we can define constant by

real root2=1.4142135;

That was much acceptable that time.

In Ada, provides a uniform notation for setting constants to initial values and for initializing variables.

X: Constant INTEGER:=17;

In C language: const is used to initialise the constant value

const int MAX=80;

The constant MAX is a programmer defined constant because the programmer explicitly defines the name for the value 30.

In C, there is micro definition which is used for control the execution of program and can be used for declaring constant.

Example #define MAX30

It is a compile-time operation that causes all references to MAX in program to be changed to the constant 30.

In this 30 has two names, the programmer defined MAX and literal name 30. Both of which may be used to refer to a data object containing the value 30.

# define MAX 30 is a command, which the translator used to equate "MAX" with the value "30", where as the const attribute in C is a translator directive starting that MAX will always contain the value 30.

09- Elementary Data Type-Constant- Programming Languages Tutorials


Facebook Likes