Can a variable be both const and volatile?
Long Answer
Views 2273
Answer:
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; }
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.