Explanatory Question
Can a variable be both const and volatile?
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.
yes, the const means that the variable cannot be assigned a new value. The value can be changed by other code or pointer. For example the following program works fine.
int main(void)
{
const volatile int local = 10;
int *ptr = (int*) &local;
printf("Initial value of local : %d
", local);
*ptr = 100;
printf("Modified value of local: %d
", local);
return 0;
}
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.