Volatile in C
Tells the compiler not to perform read optimisations on a variable, as some other thread or non-obvious code might change the variable's value. The compiler will not cache the value of the variable between reads, because other code might have changed it.
volatile tells the compiler not to perform read optimisations on a variable, as some other thread or non-obvious code might change the variable's value.
int main() {
volatile int i = 10;
int a = i;
/* some code */
int b = i;
}
The volatile qualifier tells the compiler not to cache the value of i between a and b, because other code might have changed it.
