where does a static variable inside a function get stored?? where does
it go in memory?? like Global goes in RAM, Local variable goes on
Stack... but how does static variable takes place in memory??
The C Standard does not impose any specific constraints for the
location of objects. As long as they meet the properties specified in
their declaration, the compiler is free to place them wherever it
wants.
Static objects are essentially a compromise between unqualified file
scope objects, (global), on the one hand and unqualified block scope
objects, (local), on the other hand. While they persist throughout the
program's lifetime, they're accessible only from their scope, (unless
a pointer is used). That implies that it's pretty much out of question
to place them on a stack, (except if it's declared within the main
function).
<OT>
In most implementation statics and other file scope objects are
usually placed in a section of memory called static storage. String
literals might also be placed here, or they might be placed in a read-
only area of storage. But such details are implementation specific,
you should not rely on them if you want your code to be portable. In
most cases the location of objects is quite unneccessary to know.
</OT>