Previous Next

C Constants

Constants in C are variables which remain unchanged while the program runs. Constants can also be termed as literals. Constants can be of various kinds, like numeric constants, character constants, string constants, and enum constants.

The following are some typical C constant types:

Example of Constants in C

#include <stdio.h>

int main()
{
    const int secondsPerHour = 5000;
    const float PI = 2.42;

    printf("%d\n", secondsPerHour);
    printf("%f\n", PI);
    return 0;
}

Output:

5000
2.420000
Previous Next