Q:

What is the difference between the const and volatile qualifiers in C?

0

What is the difference between the const and volatile qualifiers in C?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The const keyword is compiler-enforced and says that the program could not change the value of the object that means it makes the object nonmodifiable type. Let us see an example,

const int a = 0;

If we will try to modify the value of “a”, we will get the compiler error because “a” is qualified with const keyword that prevents to change the value of the”a” (integer variable).

Another side, volatile prevents any compiler optimization and says that the value of the object can be changed by something that is beyond the control of the program and so that compiler will not make any assumption about the object. Let see an example,

volatile int a;

When the compiler sees the above declaration then it avoids to make any assumption regarding the “a” and in every iteration read the value from the address which is assigned to the “a”.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Can a variable be both constant and volatile in C?... >>
<< What is the use of volatile keyword?...