what is volatile in c language?
Answers were Sorted based on User's Feedback
Answer / selvakumar vedhachalam
It is nothing but telling to compiler that this variable
will change its value at anytime by means of anything and
compiler should not make any assumption about this variable.
Normally compiler will assume that some variable will be
constant during runtime. This may lead error in checking a
registor value repeatedly. Because the register value may
be changed by anything. So for these kind of variables
should be declared 'volatile' and it be checked each time
appears in the code with out any assumption.
Is This Answer Correct ? | 135 Yes | 11 No |
Answer / hareesha chikkapattanager parv
It is nothing but telling to compiler that this variable
will change its value at anytime by hard or outside the
controll of the program and compiler should not make any
assumption or optimize about this variable.
Is This Answer Correct ? | 46 Yes | 5 No |
Answer / deep
consider this outside main()
int i=10;
int j = i + 10;
here smart compilers always replace the i in the second
statement with 10, when we use volatile keyword this will be
avoided and always there is a check of the i variable ,
before initialising it..
So the optimisation here is avoided
Is This Answer Correct ? | 15 Yes | 2 No |
Answer / bhagyaraj m c
Both 1 and 2 comments are correct.
Just simplifying this
"Recompute\Refresh every time when ever the volatile is
found."
Is This Answer Correct ? | 19 Yes | 7 No |
Answer / sudeep
It is nothing but telling to compiler that this variable
will change its value at anytime by means of anything and
compiler should not make any assumption about this variable.
Is This Answer Correct ? | 11 Yes | 0 No |
Answer / s.m.faisal
volatile reduces the optimization .optimization means compiler should not make out that the variable has not changed its value so it reads the value directly from the register.
So while using volatile keyword compiler will directly access the variable from the memory not from the register bcz the value of the variable can be changed outside or inside the program.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / lingaraj a
The programmer just give inform to compiler the value of
variable will change at any time without any action being by
program. The change will be made by hardware or external source.
Is This Answer Correct ? | 6 Yes | 5 No |
Answer / justin arokiaraj.r
Volatile is used for direct memory access.it can be updated by both hardware and software .so unused volatile will not be optimized in compilation
.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / greg
Volatile is a storage class that indicates that the
compiler should not perform any optimization on the
variable.
Is This Answer Correct ? | 4 Yes | 8 No |
What is a program flowchart?
#define swap1(a,b) a=a+b;b=a-b;a=a-b; main() { int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y); } int swap2(int a,int b) { int temp; temp=a; b=a; a=temp; return; } what are the outputs?
What is string length in c?
What is time null in c?
What are bitwise shift operators in c programming?
in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n
void main() { char c; while(c=getchar()!='\n') printf("%d",c); } o/p=11 why?
what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f
write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language
Reverse a string word by word??
What is scope of variable in c?