Whenever there is a local variable with the same name as that of a global variable, the compiler gives precedence to the local variable.
Example:
#include <iostream.h>
int globalVar = 2;
int main()
{
int globalVar = 5;
cout<<globalVar<<endl;
}
The output of the above code is 5. This is because, although both the variables have the same name, the compiler has given preference to the local scope.