For C Using stack, means throwing out called function variables first and then return address and then parameters. But when we use static storage class, the value of variable persists between different function calls. Stack uses last in, first out. and since function variables are last in, they should be first out but here they are not thrown out, so this means all the other information takes up memory as all... Is this how it works? But I feel this is not the most optimal way.. How are static storage class variables handled?
Asked
Active
Viewed 25 times
0
-
1Static variables are not stored on the stack. – 500 - Internal Server Error Jun 08 '20 at 13:06
-
2Does this answer your question? [What does "static" mean in C?](https://stackoverflow.com/questions/572547/what-does-static-mean-in-c) – gstukelj Jun 08 '20 at 13:07
-
I just found they are stored in Data segment. Is that where Extern variables are also stored? – Scarlet Jun 08 '20 at 15:02
-
@Scarlet: Typically, yes, but formally `extern` means that it's defined externally to the current module. – 500 - Internal Server Error Jun 08 '20 at 20:24