I am Nagavardhan Reddy, just now i started learning C Language.
Can any one tell me what exactly is Volatile qualifier.
Where and when exactly we use volatile qualifier.
What happen if i choose all variables in a program declared as Volatile.
Naga Vardhan Reddy.
Hey friend, learn to use Google. Is your first idea really to make an account on a random forum to ask a simple thing about C syntax that you could probably find thousands of explanations on?
I agree, it doesn't take much to Google what it is. I'll save you that effort: "volatile" means that the variable could change under the compiler's nose without it noticing so it should NEVER try to be clever and think it knows what it last put in there. This has a very niche usage, in multithreaded environments or programs that interact directly on a low-level with the machine (where, for example, some types of memory could be changed by, for example, an expansion card and the compiler should never assume that it HASN'T changed).
What you probably won't find on a Google is "What happen if i choose all variables in a program declared as Volatile?". The answer is that your program will run slower. Because it's completely unnecessary, and stops the compiler doing all sorts of tricks that it usually does. You're basically saying "EVERY variable in my program needs extra special care". The number of volatile's that you're likely to use unless you're programming a device driver or an operating system is approximately zero. If you NEED one, you'll know about it. Otherwise, they just destroy performance of your program.
I have never used a volatile variable in my life, even though I know exactly when they should be used (basically, shared memory or memory-mapped i/o). I'd be incredibly surprised if even most C/C++ programmers had used them, to be honest. You can see lots of them in things like the Linux kernel source code and device drivers because those people know what they are doing. Until you have a need to use them (and, trust me, you'll know), don't. They just destroy a large number of optimisations that ALL programs can benefit from.