Which keyword is used to prevent any changes in the variable within a C program?

Which keyword is used to prevent any changes in the variable within a C program?

a) static
b) const
c) volatile
d) extern

Answer:

b) const

Explanation:

The const keyword in C is used to declare a variable as constant, meaning its value cannot be changed once it has been initialized. If you attempt to modify a const variable after its initialization, the compiler will generate an error. This is useful for defining values that should remain constant throughout the program, such as mathematical constants or configuration values.

Understanding the const keyword is crucial for ensuring that certain values in your program are protected from accidental modification, enhancing the program’s reliability and integrity.

Reference links:

https://www.rameshfadatare.com/learn-c-programming/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top