volatile keyword in c
Using volatile Keyword is yet another way (like synchronized,
atomic wrapper) of making class thread safe. Thread safe
means that a method or class instance can be used by
multiple threads at the same time without any problem.
4.4
5
C's volatile keyword is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby.
Thank you!
5
0
4.25
4
//volatile keyword usage in C
#include<stdio.h>
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;
}
Thank you!
4
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
C 2022-03-27 18:30:08 how to free memory in c
-
C 2022-03-27 18:00:14 linux command line windows
-
C 2022-03-27 18:00:02 C example of if else
-
C 2022-03-27 17:10:18 sum of digits in c using for loop
-
C 2022-03-27 12:35:50 replace word in c
-
C 2022-03-27 07:40:11 How to setup a line length marker in vim
-
C 2022-03-27 07:35:09 Multi Select with icons htm;