soodsandeep
asked on
accessing global variable in c.
hello.
in c++ we have :: operator to acess global variable ( if we have a local variable with the same name as that of global variable).
BUT how does we access such a global variable in c?
e.g
int x;
main()
{
int x;
:
:
}
how do i access global x in main()
in c++ we have :: operator to acess global variable ( if we have a local variable with the same name as that of global variable).
BUT how does we access such a global variable in c?
e.g
int x;
main()
{
int x;
:
:
}
how do i access global x in main()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi soodsandeep,
You shouldn't do this, anyway. It's not good programming style. Since C lacks C++'s namespaces, you'd normally prefix globals, or store them in a global structure - it's less pollution of the global namespace.
Cheers!
Stefan
You shouldn't do this, anyway. It's not good programming style. Since C lacks C++'s namespaces, you'd normally prefix globals, or store them in a global structure - it's less pollution of the global namespace.
Cheers!
Stefan
You can by using pointers that point to the original variable but that is not really any point.