HOME LIBRARY C++ PHP JAVA HTML
CSAdeeb

Symbolic Constants in C

Symbolic constants in C programming are some symbols or labels that hold a constant value during the program execution. The values of symbolic constants do not change during the program execution.

Defining Symbolic Constants in C

In the C language, the symbolic constants are defined using the keyword #define.

Examples:

#define PI 3.141593
#define MAX 80

Above statements are preprocessor statements. When the program is preprocessed, all the appearance of PI is replaced by the value 3.141593 and the appearance of MAX is replaced by 80.

Usually, in C programming symbolic constants are defined just above the main function. Note that preprocessor statements are not ending with a semicolon.

Consider the below program:

#include <stdio.h>
#define PI 3.141593
void main()
{
  int radius = 6;
  float area = PI * radius * radius;
  printf("The Area is : %f ",area);
}

In the above program, the value of the area is calculated as 3.141593 × 6 × 6.