What are constants in C?
a) Fixed values that do not change
b) Variables that change frequently
c) Functions
d) None of the above
Answer:
a) Fixed values that do not change
Explanation:
Constants in C are fixed values that do not change during the execution of a program. They are defined using the const
keyword or #define
directive. Constants can be of any data type, such as int
, float
, char
, etc. Once defined, their values cannot be altered, making them useful for representing unchanging data, such as mathematical constants (e.g., PI
) or configuration values.
Using constants improves the readability and maintainability of code by making it clear that certain values are meant to remain unchanged throughout the program. It also helps prevent accidental modification of critical values.