Constants in C
Our program demonstrates the use of constants in C. Here’s the full source code:
In C, we use #define
to declare symbolic constants and const
to declare constant variables.
The #define
directive is used to create a symbolic constant S
with the value “constant”.
A const
variable can be declared anywhere a regular variable can be declared.
Constant expressions perform arithmetic with the precision of the types involved.
In C, constants typically have a specific type. When needed, we can use explicit type casting.
Functions from math.h
, like sin()
, expect double
arguments by default.
To compile and run this program:
Note that we need to link the math library (-lm
) when compiling.
C constants provide a way to define values that don’t change throughout the program, improving readability and maintainability.