Class 6 Exam  >  Class 6 Questions  >  Which keyword is used to prevent any changes ... Start Learning for Free
Which keyword is used to prevent any changes in the variable within a C program?
  • a)
    immutable
  • b)
    mutable
  • c)
    const
  • d)
    volatile
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
Which keyword is used to prevent any changes in the variable within a ...
The correct answer is option 'C': const.

Explanation:
In C programming, the keyword 'const' is used to declare a variable as a constant. When a variable is declared as 'const', it means that its value cannot be changed throughout the program execution. The 'const' keyword is used to indicate that a variable's value is read-only and cannot be modified.

The 'const' keyword is known as a type qualifier, which modifies the type of the variable. It can be applied to any data type such as int, float, char, etc. When a variable is declared as 'const', it must be assigned a value at the time of declaration, and this value cannot be modified later in the program.

Using the 'const' keyword has several benefits:
1. Readability: It makes the code more readable by clearly indicating that a variable is meant to be constant.
2. Avoid accidental modifications: It prevents accidental modifications of the variable's value, ensuring that the intended value remains constant throughout the program.
3. Optimization: The 'const' keyword allows the compiler to perform optimizations, as it knows that the value of the variable will not change. This can lead to improved performance in some cases.

Example:
```c
#include

int main() {
const int num = 5; // declaring 'num' as a constant

printf("num = %d\n", num);

// Trying to modify the value of 'num' will result in a compile-time error
num = 10; // Error: assignment of read-only variable 'num'

return 0;
}
```

In the above example, the variable 'num' is declared as a constant using the 'const' keyword. When we try to assign a new value to 'num', it will result in a compile-time error because the variable is read-only.
Free Test
Community Answer
Which keyword is used to prevent any changes in the variable within a ...
const is a keyword constant in C program.
Explore Courses for Class 6 exam
Question Description
Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? for Class 6 2025 is part of Class 6 preparation. The Question and answers have been prepared according to the Class 6 exam syllabus. Information about Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Class 6 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer?.
Solutions for Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 6. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.
Here you can find the meaning of Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Which keyword is used to prevent any changes in the variable within a C program?a)immutableb)mutablec)constd)volatileCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Class 6 tests.
Explore Courses for Class 6 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev