Symbolic constant in C language
Symbolic constant is a name that substitutes for a sequence of characters which may be numeric constant , character constant or a string constant.
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 program just after header files.
Syntax for symbolic constant
#define name text
#define PI 3.1415
#define LETTER 'y'
#define NAME "john"
Note : Character is enclosed in single quote 'y' and String ( character array ) is enclosed in double quote "john".
Where name represents a symbolic name , usually written in uppercase letters and text represents sequence of character and doesn't end with semicolon .
if semicolon is added then compiler treat it as a part of text
like #define PI 3.14;
compiler replaces all "PI" with "3.14;" during compilation so never put semicolon at the end of text.
After definition of symbolic constant at the beginning of program you can use it letter like below
area = PI * radius * radius;
Advantages of symbolic constant in c