The Question: If a name has two different meanings (i.e., declarations): one in an "outer" block and one in a nested "inner" block, and the name is accessed within the inner block, which meaning is accessed?
Hypothesis: Review the rules of scope, and then construct a hypothesis.
The Experiment:
If we display the value of arg1 within the inner block,
following its redeclaration, we can get an answer to our question:
int main()
{
int arg1;
arg1 = -1;
...
{
char arg1 = 'A';
cout << '\n' << arg1 << endl;
}
}
If, upon running the program, we see -1 displayed, then the int
meaning is being accessed, while if we see A displayed, then
the char meaning is being accessed.
Observation: Translate and run your source program. What is displayed?
Conclusions: Review the rules of scope and explain what happened.
Forward to the Next Experiment