Both Static and Global variables in C are stored in Data segment ( Uninitialized or Initialized ) but Static variable scope is only that file or that function and global variable scope is whole program and both variables life is whole program how it is implemented. They are stored in same segment even though how they different in behavior.
Share
Even both are in the data segement there is a difference ,
staticvariables hasinternal linkageandglobalhasexternal linkage(by default) that’s why static is visible in the current translation unit but globals are visible in others.By declaring variables static (which are in global scope), It means you are restricting the variable to the current file only.
Also initialzed and uninitialized variables are stroed in two different segement
here is the actual segmentation for every variables and code for a program.
2
In the set of translation units and libraries that constitutes an entire program, each
declaration of a particular identifier with
external linkagedenotes the same object orfunction. Within
one translation unit, each declaration of an identifier withinternaldenotes the same object or function. Each declaration of an identifier withlinkage
nodenotes a unique entity.linkage
3
If the declaration of a file scope identifier for an object or a function contains the storageclass
specifier
static, the identifier hasinternal linkage.22)