I am trying to understand how compiler know the correct location of variables when there are multiple variables with same name is given in program. I found the scope of variables depends on linkage.
Take a look at code. I have written the linkage of each variable in the comments.
Take a look at code. I have written the linkage of each variable in the comments.
C:
#include<stdio.h>
int x; // variable x with external linkage
static int y; // variable y with internal linkage
extern int y; // variable y with external linkage
void foo()
{
int x; // variable x with internal linkage.
static int y; // variable y with internal linkage
}
int main()
{
int x; // variable x with no linkage
return 0;
}