Define constant. Describe the constant type with proper example.
Subject | Programming Language |
---|---|
NU Year | Set: 2.(a) Marks: 5 Year: 2013 |
In computer
programming, a constant is a value that cannot be altered
by the program during normal execution, i.e., the value is constant. When
associated with an identifier, a constant is said to be "named,"
although the terms "constant" and "named constant" are
often used interchangeably. This is contrasted with a variable, which
is an identifier with a value that can be changed during normal execution,
i.e., the value is variable. Constants are useful for both
programmers and compilers: for programmers they are a form of self-documenting code
and allow reasoning about correctness; while for compilers they
allow compile-time and run-time checks that constancy
assumptions are not violated, and allow or simplify some compiler
optimizations.
const float PI = 3.1415927; // maximal single float precision
const unsigned int MTU =
1500; // Ethernet v2, RFC 894
const unsigned int COLUMNS
= 80;