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

typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

0 Answers  


what is the difference between embedded c and turbo c ?

1 Answers  


Explain what are run-time errors?

0 Answers  


What is the g value paradox?

0 Answers  


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

0 Answers  






Can you apply link and association interchangeably?

0 Answers   InterGraph,


What should malloc(0) do?

0 Answers  


which operator is known as dummy operator in c?

2 Answers   Wipro,


What is build process in c?

0 Answers  


The OS is a program that uses various data structures. Like all programs in execution, you can determine the performance and other behavior of the OS by inspecting its state - the values stored in its data structures. In this part of the assignment, we study some aspects of the organization and behavior of a Linux system by observing values of kernel data structures exposed through the /proc virtual file system. The /proc virtual file system: Linux uses the /proc file system to collect information from kernel data structures. The /proc implementation provided with Linux can read many different kernel data structures. If you cd to /proc on a Linux machine, you will see a number of files and directories at that location. Files in this directory subtree each corresponds to some kernel data structure. The subdirectories with numeric names contain virtual files with information about the process whose process ID is the same as the directory name. Files in /proc can be read like ordinary ASCII files. You can open each file and read it using library routines such as fgets() or fscanf(). The proc (5) manual page explains the virtual files and their content available through the /proc file system. Requirements in detail: In this part, you are asked to write a program to report the behavior of the Linux kernel. Your program should run in two different versions. The default version should print the following values on stdout: • Processor type • Kernel version • The amount of memory configured into this computer • Amount of time since the system was last booted A second version of the program should run continuously and print lists of the following dynamic values (each value in the lists is the average over a specified interval): • The percentage of time the processor(s) spend in user mode, system mode, and the percentage of time the processor(s) are idle • The amount and percentage of available (or free) memory • The rate (number of sectors per second) of disk read/write in the system • The rate (number per second) of context switches in the kernel • The rate (number per second) of process creations in the system If your program (compiled executable) is called proc_parse, running it without any parameter should print out information required for the first version. Running it with two parameters "proc_parse <read_rate> <printout_rate>" should print out information required for the second version. read_rate represents the time interval between two consecutive reads on the /proc file system. printout_rate indicates the time interval over which the average values should be calculated. Both read_rate and printout_rate are in seconds. For instance, proc_parse 2 60 should read kernel data structures once every two seconds. It should then print out averaged kernel statistics once a minute (average of 30 samples). The second version of your program doesn't need to terminate.

0 Answers   Cognos,


What is use of integral promotions in c?

0 Answers  


the expression a=30*1000+2768; evalutes to a) 32768 b) -32768 c) 113040 d) 0

1 Answers  


Categories