![]() |
| ||
| Scope Problem Plz look at this code #include<iostream.h><< moderator edit: added [code][/code] tags >> does anybody know how can i access main local variable x, from inside the block, without using pointers or references? |
| ||
| Re: Scope Problem You could always just use better variable naming conventions. Using "x" for the name of every variable doesn't help you, and it doesn't help anybody looking at your code. |
| ||
| Re: Scope Problem Well...this was the question asked to me in my viva exam...and i think having same name in different scopes makes the question more tricky |
| ||
| Re: Scope Problem Your problem contains the ans. Quote:
|
| ||
| Re: Scope Problem I guess u didn't understood what i was asking.....i am not talking about the global variable ....iam talking about the local variable inside the main....but thanx anyways i was able to solve this problem |
| ||
| Re: Scope Problem What's the solution? I mean how do you access the variable inside the main from the inner block? |
| ||
| Re: Scope Problem you cant. watch. int x=0; // global xThe basic rule is a name in an inner scope hides the name in all outer scopes unless the scope resolution operator can be used to access it which is not possible with function scope local variables. |
| ||
| Re: Scope Problem Quote:
Yes you can Here is the solution #include<iostream.h> |
| ||
| Re: Scope Problem >Yes you can Once you realize that it's a stupid trick question, of course. ;) |
| All times are GMT -4. The time now is 2:34 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC