What is the purpose of the ‘const’ keyword in C?
a) To declare a constant variable that cannot be changed
b) To define a function
c) To declare a loop variable
d) To return a value from a function
Answer:
a) To declare a constant variable that cannot be changed
Explanation:
The const
keyword in C is used to declare a variable whose value cannot be changed after it has been initialized. This is useful for defining constants that represent fixed values, such as mathematical constants or configuration values, which should not be altered during program execution.
Understanding the const
keyword is important for ensuring that certain variables remain unchanged, which can help prevent bugs and improve code reliability.