What is the use of volataile variable ? when we need to delcare a varaible as volataile ?

Showing Answers 1 - 4 of 4 Answers

someone

  • Aug 31st, 2006
 

a variable is to declared volatile , if the value of the variable is expected to change between two consecutive reads

eg: voilatile int i;

x

  Was this answer useful?  Yes

someone

  • Aug 31st, 2006
 

a variable is to be declared volatile , if the value of the variable is expected to change between two consecutive reads

eg:

voilatile int i;

int x;

x = i;

printf("%d",x);

x = i;

printf( "%d",x);

the value of x would be different each time, i.e., the value of i has changed between 2 consecutive reads , maybe becuase of some interrupt...etc

since it is declared volative the compilers do no optimization

  Was this answer useful?  Yes

Techie

  • Sep 2nd, 2006
 

Volatile is a keyword used to specify to the compiler not to optimize the access to the particular variable(defined as volatile). This is mostly useful in

 I)places the variable is used to refer to a pointer to device register.

2) If a global variable is set in an ISR and verified/accessd in a function.

3) If an address location is shared between different tasks.

  Was this answer useful?  Yes

tej

  • Sep 4th, 2006
 

using volatile option doesnt put the variable in cache so there is will no time delay in updation of the register value hence when the variable is read frequently its declared as volatile

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions