C Constants

C Constants are the identifiers that once defined, cannot be modified. C Constants can either be defined using #define preprocessor or using const keyword. Like C Variables, C Constants name can only be started with a letter or an underscore only.

C #define preprocessor:

Syntax:

#define Constant_name Constant_Value;

  • Constant Name: This parameter is used to specify the name of the constant.
  • Constant Value: This parameter is used to specify the value of the constant.

C const keyword:

C const keyword is another method to define constants during compilation.

Example 1: Defining C Constants using #define preprocessor

#include <stdio.h>
#define AGE 30
void main()
{
printf ("%d", AGE);
}

Output

30

Example 2: Defining C Constants using const keyword

#include <stdio.h>
void main()
{
const int AGE = 30;
printf ("%d", AGE);
}

Output

30
Please follow and like us:
Content Protection by DMCA.com