he volatile qualifier is applied to a variable when we declare it. It is used to tell the compiler, that the value may change at any time. These are some properties of volatile code example

Example: declaring a volatile in c

//volatile keyword usage in C
#include

int main(){
    //different methods of declaring and initializing volatile variables

    //method 1 - volatile int
    int volatile number1 = 10;

    //method 2 - volatile int
    volatile int number2;
    number2 = 20;

    //method 3 - volatile pointer
    int volatile *p1;
    p1 = &number1;

    //method 4 - volatile double pointer
    volatile int **p2;
    p2 = &p1;
    
    printf("%d %d %d %d",number1,number2,*p1,**p2);
    return 0;
}

Tags:

Misc Example