Amazon Interview Question
Software Engineer / Developersstatic variables are stored in BSS segment. BSS - Block started by Symbol. It exists in the lower part of data segment and the variables stored here are initialized to ZERO. So, if you declare as static int i; then i is stored in BSS segment.
If two functions say
function1 () {
static int i;
...
}
function2 () {
static int i;
...
}
it will not be stored in the BSS as two integer i's simply. Every variable will be mapped and stored with the function name and the variable name in the symbol table by the compiler. So, int i of function1 will be stored something like - f1:i (depends on compiler). So there wont be any conflict even if the same variable name is declared in multiple functions.
moreover in data segment , static variables are stored for each function differently , so if there are multiple function delaring the same static variable , then in data segment , they are stored for each funciton differently .
- tom September 07, 2008u can see the dump by using nm command .