top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: Difference between constant and volatile qualifier?

+1 vote
1,016 views

Also can we declare a variable as "constant volatile" ? if yes then what may be the possible reason to do so?

posted Jun 23, 2014 by Ganesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Constant: Constant means the value of the variable can not be changed in the program.
Volatile: Volatile tells the compiler not to optimize anything that has to do with the volatile variable.

Now coming to the second problem check the following statement

const volatile int T=10;

const qualifier means that the T cannot be modified through code. If you attempt to do so the compiler will provide a diagnostic. Volatile still means that compiler cannot optimize or reorder access to T.

Practical Usage:
Accessing shared memory in read-only mode.
Accessing hardware registers in read-only mode.

answer Jun 23, 2014 by Salil Agrawal
0 votes

constant means values is not change but volatile values is changes in any time.

String str="ramsevak" values in not change this is a constant values of str

but int a=10;
a=a+10;
the values is changes so a is a volatile.

answer Jun 23, 2014 by anonymous
Similar Questions
+7 votes

Where we need to use volatile variable? If possible please provide some real time example ?

+6 votes

Let me put this in other way , const qualifier will not allow to change you the value so what is the need of going with const volatile. Do we really need it in our day to day programming

...