top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Can a variable be both const and volatile in C?

+3 votes
Can a variable be both const and volatile in C?
posted Oct 21, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
please can you tell the usage of this statement. If we know that variable may change at run time then then why should specify as constant ?.
Is this question on me or on whoever asked the query.
To the person who asked the  query.
That's what my question, what is the significance of volatile on the const variable, though Mr Salil logic seems to be making sense. Thanks :)

1 Answer

+1 vote


Volatile keyword tells the compiler that the value of the variable can change (may be frequently) so that it can avoid the optimization.

Constant means variable can not be assigned a new value the catch here is using the pointer we can change the value. So when we say a variable is both a constant and volatile that means we are instructing the compiler that the variable can not be assigned a new value and its value can be changed by the use of pointer so don't do any optimization.

answer Oct 21, 2014 by Salil Agrawal
Similar Questions
+1 vote

In large product based companies LLD is written by senior team members and developers write the code.
Does the senior team member decide what data type they should use in advance ? If yes then what things derives type of data for example. How they decide a variable should be declared as volatile ? and what would be advantage of having a variable volatile and what could be the problem if it is taken without the volatile ?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.