what is difference b/w extern & volatile variable??

Answers were Sorted based on User's Feedback



what is difference b/w extern & volatile variable??..

Answer / antonio leite

extern states that a variable is referenced in a module but
is declared in another module. This makes the linker not
generate an error/warning when the extern variable is
referenced but wait till the declaration is stated in a
module.
volatile states that the value of a variable can be changed
anywhere in the code. This is used by the optimizer to know
that a piece of code must not be optimized when a volatile
variable is found. For example, when a variable is changed
by a interrupt timer it must be declared volatile. The code
seems to be always true because Timer_xpto seems to be
always > 0. If the code is optimized, the if would simply
disapper from the code, but this is not what the programmer
wants, so declare
extern volatile unsigned long Timer_xpto;
so that the compiler will never optimize the code below.

Timer_xpto = 100;
do something
if (Timer_xpto > 0 )
{
do any other thing
}

Here extern is stating that the variable is declared in
other module and volatile that the code where the
Timer_xpto appears must not be optimized.
See http://www.eetimes.com/discussion/programming-
pointers/4025609/Place-volatile-accurately

Is This Answer Correct ?    13 Yes 0 No

what is difference b/w extern & volatile variable??..

Answer / sathya

extern keyword is used to strike the global declaration.
but volatile its indirectly change the values in externally

Is This Answer Correct ?    5 Yes 1 No

what is difference b/w extern & volatile variable??..

Answer / mchilakala

Extern keyword specifies that the variable had been
declared globally where as volatile keyword specifies that
there is a chance of changing it's value by external
conditions.
Ex:
if we declare a variable as

"Volatile date=03/08/2011"
then output is 03/08/2011
then after one day the output will change to 04/08/2011.

Is This Answer Correct ?    3 Yes 0 No

what is difference b/w extern & volatile variable??..

Answer / anonimos

volatile variables are used on RT Embedded systems to
interface a physical memory mapped/IO mapped cell on the
computer board (volatile pointer).

Example define IO port:
#define PortA (*(volatile unsigned char *)0x3b)
unsigned char inputValue=PortA;

optimization may attempt to perform paging to hard drive of
to cache or even CPU registers so when reading from the
physical location in Mem/IO space the program will actually
read old value that was paged/cached by optimization
algorithm of the computer/board, even after the Input
changed on this Memory/IO cell.

volatile instruct the compiler to prevent optimization by
caching to registers/cache.

Is This Answer Correct ?    1 Yes 0 No

what is difference b/w extern & volatile variable??..

Answer / mani

extern variables are stored in CPU ,volatile variables are
temporary.

Is This Answer Correct ?    4 Yes 10 No

what is difference b/w extern & volatile variable??..

Answer / deepa

extern is a keyword used to declare variables as global
varible.volatile variables are temporary variable

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More C Interview Questions

Go through this linked list concept.While traversing through the singly linked list sometimes the following code snippet "while(head != NULL)" is used and other times "while(head->link != NULL)"is used(Here head is the pointer pointing to the first node,node has two parts data part and link part).What is the difference between head != NULL and Head->link != NULL and in which situation are they used?

1 Answers   Oracle,


What is #include conio h?

0 Answers  


Why the below program throughs error during compilation? #include<stdio.h> #include<conio.h> enum { ZERO, ONE, TWO, }; main() { printf("%d",&TWO); getch(); }

2 Answers  


When should you not use a type cast?

0 Answers  


plz answer..... a program that reads non-negative integer and computes and prints its factorial

2 Answers  






how does the C compiler interpret the following two statements p=p+x; q=q+y; a. p=p+x; q=q+y b. p=p+xq=q+y c. p=p+xq; q=q+y d. p=p+x/q=q+y

2 Answers   TCS, Tech Synergy,


what is the difference between declaration and definition of a variable or function ?

3 Answers  


write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

0 Answers  


What is difference between function overloading and operator overloading?

0 Answers  


#define DCHAR char* typedef char* TCHAR; if using these following variables will be declared like DCHAR ch1, ch2; TCHAR ch3, ch4; then what will be types of ch1, ch2, ch3 and ch4?

6 Answers   NDS,


What is function definition in c?

0 Answers  


c program to input values in a table(using 2D array) and print odd numbers from them

1 Answers  


Categories