+ 2
What is difference between static and global variable in C?
Since both static and global variables can be used anywhere in whole code ,then what really is the thing differentiating them?
7 Respostas
+ 2
On Sololearn you won't observe a difference. In real development the difference arises when you are working with multiple source code files. Use static to declare that a variable is only global to the source file it is contained in. A static global won't be recognized outside of its source file, wheres an unqualified global can be visible in the entire project. In that case you would use the extern keyword to declare that is defined elsewhere.
https://stackoverflow.com/questions/7837190/c-c-global-vs-static-global#7837369
+ 2
Arsenic eghh ... i was talking about the const variables .. ma bad
+ 1
M.A.G can you provide an example where changing global variable caused compiler error ?
+ 1
They're both stored in the data segment; the difference is that the global has an externally-visible linker symbol, and the static global does not.
0
so global applies to the whole program and is always active, static is locked in a function and has to be called separately where is needed?