A symbolic constant is a name that substitutes for a
sequence of characters. The characters may represent numeric constant, a
character constant or a string constant. Thus, a symbolic constant allows a
name to appear in place of a numeric constant, a character constant or a
string. When a program is compiled, each occurrence of a symbolic constant is replaced
by its corresponding character sequence. Symbolic constants are usually defined
at the beginning of a program. The symbolic constants may then appear later in
the program in place of the numeric constants, character constant, etc that the
symbolic constants represent.
A symbolic constant is defined by writing
#define name text
Where name represents a symbolic name, typically
written in uppercase letters, and text represents the sequence of characters
that is associated with the symbolic name. It doesn’t require semicolon. For
example
#define TAXRATE 0.13
#define PI 3.141593
#define TRUE 1
#define FALSE 0
#define FRIEND “Susan”
area = PI * radius * radius; is equivalent to
area = 3.141593 * radius * radius ;
Comments
Post a Comment