In which memory segment a program global and local static variables are saved
As far as I know global static variables are stored in .Data and .Bss
segment.
(global) static int i; ---> .BSS
(global) static int i=10; ---> .Data
If this is the case how multiple files which have same global staic
variables access the variables from a memory location which is common to
whole program.
Ex.
test.c
static int i=10;
void fun(){
printf("%d", i );
}
test1.c
static int i=20;
void fun1(){
printf("%d", i);
}
How test.c and test1.c resolve i from .Data segment?
My second question is in which segment of the program memory local static
variables defined inside a functions are stored?
No comments:
Post a Comment