Thomas Hruska <[EMAIL PROTECTED]> wrote:
> Vivek Shivu wrote:
> > int a=20; // Global variable
> > int main()
> > {
> > clrscr();
> > {
> > int a; // Local Variable
> > a=10;
> > printf("Local Variable = %d \n",a); // It prints 10 LocalVariable Value
> > }
> > printf(" global Variable Value = %d\n",a); // It should print Global
> > Variable Value
> > getch();
> > }
> >
> >
> > this is based on the life of a variable within a block....
> > hope tis helped u.....
> >
> > Vivek
>
> Oops. I keep forgetting about block level scope locality.
>
> It is just better to not create names that collide with each other.
> Then you don't have to worry about it.
OP, you can do this in different ways. But all are dirty.
You can even have pointer to the global varible before declaring
local varible and other different ways: *all bad, forget bout them
all*
What you should be doing is to have a namespce for your global
varible. That's the cleanest implementation I can think of. No issues,
you have to specify which var you are accessing.
btw, "a" is not working on my keyboard, went and purchased a new
Logitech keyboard. Very bad quality, keyboard keeps getting
disconnected, I have to physically reconnect the keyboard every few
minutes. Hfta go get replacement.
Try pasting "a" instead of typing "a", its a BIG pain in the wrong place
- Ananth