Is it possible to declare a variable as both const and volatile in c?
Either we can declare as const or volatile, but not together.
we can declare as volatile const, but not in revser order.
Yes, we can declare a variable as const volatile.
we can declare a variable as const for constants, but there is nothing like volatile in c.
Yes, we can declare a variable as const volatile. volatile keyword will be used if a variable has to be changed or accessed from some outside system environment. eg: if we a have variable to keep track of timer, then that variable might be monitored or changed or accessed by system's ticker clock which is not part of our program. in that case we have to declare that variable as volatile. If we don't want that variable to be modified (read only) then we can make it as const. so const volatile together also makes sense.
Back To Top