Vidyalelo
C Programming · Q20

C Fundamentals

Programming · C Programming · question 20

Q20

What is the purpose of the 'const' keyword in C?

A.
Declare a constant
Answer
B.
Declare a variable
C.
Define a function
D.
Initialize a pointer

Answer: Option A

Solution

Answer: Option A
Solution:
The purpose of the 'const' keyword in C is to declare a constant. When you use the 'const' keyword before a variable declaration, it indicates that the value of that variable cannot be changed once it is assigned a value. It creates an immutable constant in your code.

So, the correct answer is:
Option A: Declare a constant
Here's an example of using the 'const' keyword to declare a constant in C:
const int max_attempts = 3;

In this example, 'max_attempts' is declared as a constant integer, and its value cannot be modified after initialization.