How are static variables stored in memory!!!

micsom's Avatar, Join Date: Oct 2008
Go4Expert Member
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..
#include <stdio.h>
int fun1();
int fun2();
int main (int argc, const char * argv[]) {
    // insert code here...
    printf("Hello, World!\n");
    return 0;
int fun1(){
	static int i=1;
	return 1;
int fun2(){
	static int i=2;
	return 1;
xpi0t0s's Avatar, Join Date: Aug 2004
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.