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 |
Explain how do you determine the length of a string value that was stored in a variable?
How can a process change an environment variable in its caller?
b) 4 c) 6 d) 7 32. Any C program a) must contain at least one function b) need not contain ant function c) needs input data d) none of the above 33. Using goto inside for loop is equivalent to using a) continue b) break c) return d)none of the above 34. The program fragment int a=5, b=2; printf(“%d”,a+++++b); a) prints 7 b)prints 8 c) prints 9 d)none of the above 35. printf(“ab” , “cd”,”ef”); prints a) ab abcdef c) abcdef, followed by garbage value d) none of the above 36. Consider the following program segment. i=6720; j=4; while((i%j)==0) { i=i/j; j=j+1; } On termination j will have the value a) 4 b) 8 c) 9 d) 6720
Which is best book for data structures in c?
How many levels of indirection in pointers can you have in a single declaration?
0 Answers Agilent, ZS Associates,
what is ans for this scanf(%%d",c);
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
i need all types of question paper releted to "c" and other language.
What is the diffences between Windows XP and Windows Visa
How to implement variable argument functions ?
Do variables need to be initialized?
Can a pointer be volatile in c?