initialized static variables are stored in the Data segment, but in that case there will be two copies of static int i in the data segment according to the given code below, but how is it possible??..can some1 please tell me how are they stored in the memory, because this program is working fine.. Code: #include <stdio.h> int fun1(); int fun2(); int main (int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); fun1(); fun2(); return 0; } int fun1(){ static int i=1; printf("i=%d\n",i); return 1; } int fun2(){ static int i=2; printf("i=%d\n",i); return 1; }
A variable name only represents a location in memory. Since each i is in a different function the compiler can tell the difference and there is no conflict. Variable storage only stores the value, not the name.