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:
- Integer Constants: Numbers with representations as decimals (base 10), hexadecimals (base 16), binary (base 2), or octals (base 8) are referred to as integer constants.
- Floating-Point Constants: Real numbers with an exponent or a decimal point are given as floating-point constants.
- String Constants: String constants are in double quotes, for example, "Hello, Coders".
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