-
Shadow variable value
Hi ,
Is there any way to get the value of a global variable to a method in C which has the same variable declared in it ? For eg:
Code:
#include <stdio.h>
# include <conio.h>
int i=4;
int main()
{
int i=5;
printf(" i is %d ",i );
getch();
}
Is there any way to get the value of the global variable i=4 in the method main() which is possible in C++ (using scope resolution operator)
-
-
The workaround, however, is simple: change the name of the local variables within the function. Rationale: if you have a function that needs to do this, you have access to the implementation of that function, and can therefore change the names of local variables to your hearts content.