Link to home
Start Free TrialLog in
Avatar of soodsandeep
soodsandeepFlag for India

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()
Avatar of SilkyShark
SilkyShark

You can't with a 'normal' language construct.
You can by using pointers that point to the original variable but that is not really any point.
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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