What is an volatile variable?

Answers were Sorted based on User's Feedback



What is an volatile variable?..

Answer / satish

if a variable is declared as volatile ,optimization is not
done regarding to that variable.If the value is modified
many number of times,each time CPU goes and reads from main
memory rather than cache memory.
The usage of this can be
understood clearly only at kernel level but not at
application level.

Is This Answer Correct ?    36 Yes 2 No

What is an volatile variable?..

Answer / babu

Declaraton an obj const announces that its value will not
be changed;declaring it Volatile announces that it has
special properties relevent to optimization[change].

Is This Answer Correct ?    28 Yes 4 No

What is an volatile variable?..

Answer / agung bakhtiar

A volatile variable is the one whose values may be changed at any time by some external sources

Is This Answer Correct ?    18 Yes 1 No

What is an volatile variable?..

Answer / shenbagavalli

The volatile keyword is a type qualifier used to declare
that an object can be modified in the program by something
such as the operating system, the hardware, or a
concurrently executing thread.

Is This Answer Correct ?    15 Yes 0 No

What is an volatile variable?..

Answer / chandrashekar kalvacherla

volatile tells the compiler that this variable can get altered by ways that the compiler cannot deduce. As a consequence, the compiler will exclude that variable from optimizations and the code will always fetch the variables content from memory, even if it has done so before (no caching).

Imagine a hardware clock which is mapped into memory. You need some way to tell the compiler: whenever I access that variable (mapped to the hardware clock), I want you to actually fetch the content from there. Otherwise the compiler might just ask the clock once for the current time and use the cached value (in a processor register) throught the rest of the program.

Is This Answer Correct ?    8 Yes 0 No

What is an volatile variable?..

Answer / srividya

A volatile variable is variable whose value can change with
out the knowledge of the compile. so the data access
optimization is lost.
These sort of variable are used normally accessing a global
variable between two threads.

Is This Answer Correct ?    3 Yes 0 No

What is an volatile variable?..

Answer / vivek satasia

IT IS SUCH A VARIABLE WHICH IS NOT MODIFIED BY ITS PROGRAM
BUT IT CAN BE MODIFIED OUTSIDE PROGRAM ENVIRONMENT.

Is This Answer Correct ?    6 Yes 4 No

What is an volatile variable?..

Answer / priya

In computer programming,a variable or object declared
with the volatile keyword may be modified externally
from the declaring object. Variables declared to be
volatile will not be optimized by the compiler
because the compiler must assume that their values
can change at any time.

Is This Answer Correct ?    1 Yes 0 No

What is an volatile variable?..

Answer / vinod

the variable which can be modify

Is This Answer Correct ?    0 Yes 0 No

What is an volatile variable?..

Answer / vishal

What is the significance of volatile keyword?
Volatile keyword is used to inform the compiler not to predict/assume/believe/presume the value of the particular variable which has been declared as volatile.



Why/When do we need volatile ?
In following case we need to use volatile variable.




Memory-mapped peripheral registers
Global variables modified by an interrupt service routine
Global variables within a multi-threaded application
If we do not use volatile qualifier the following problems may arise:




Code that works fine-until you turn optimization on
Code that works fine-as long as interrupts are disabled
Flaky hardware drivers
Tasks that work fine in isolation-yet crash when another task is enabled

Source: http://www.firmcodes.com/volatile-keyword-in-c-and-embedded-system/

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is variable in c with example?

1 Answers  


int i; i=2; i++; if(i=4) { printf(i=4); } else { printf(i=3); } output of the program ?

15 Answers   Mascot,


to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?

0 Answers  


What is the output for the below program? void main() { float me=1.1; double you=1.1; if(me==you) printf("love c"); else printf("know c"); }

7 Answers  


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

0 Answers  






what is Structural oriented language? give some example of this language.....?

1 Answers  


Write a c pgm for leap year

11 Answers   College School Exams Tests, IBM, TCS,


what is the size of an integer variable?

4 Answers  


Tell me what is the purpose of 'register' keyword in c language?

0 Answers  


write a program of bubble sort using pointer?

3 Answers   TCS,


write a function that accepts an integer/char array and an search item.If the search item is there in the array return position of array and value else return -1.without using other array,without sorting,not to use more than one loop?

3 Answers   Mind Tree,


Write a c program for sum of first n terms of the series S = 1 - (1/3) + (1/5) -(1/7) + (1/9) ......

2 Answers  


Categories