#include<stdio.h>
#include<conio.h>
int main()
{
volatile int x;
volatile const int y=10;
printf("Enter an integer:");
scanf("%d",&x);
printf("Entered integer is :%d",x);
x=3;
printf("\n Changed value of x is :%d",x);
printf("\n Value of y: %d",y);
getch();
}
/*The volatile variables are those variables that can be changed at any time by other external program
or the same program.*/
In the above program, “x” is declared as a volatile variable, which means that its value can be modified by other external factors. The user is prompted to enter an integer which is then assigned to the variable “x” using the scanf() function. The entered value is then displayed using the printf() function. Then the value of “x” is changed to 3 and displayed again. The variable “y” is also declared as a volatile variable with a constant value of 10, which is displayed using the printf() function. The keyword “volatile” informs the compiler that the value of the variable may change at any time and it should not perform any optimization based on the value of the variable.
Thanks
Write a program to demonstrate wrapping around (volatile variables).