course.wilkes.edu/CS125Labs
Welcome to the site for CS 125 labs!

 

Experiment 10: auto Scope, Part IV

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 outer 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 following 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 your source program. What is displayed ?





Conclusions: Review the rules of scope and explain what happened.





 
  Home

Help

Lab 0

Lab 1

Lab 2

Lab 3a

Lab 3b

Lab 4

Lab 5

Lab 6

Lab 7

Lab 8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13



Membership

Login




Last update: Wednesday, August 23, 2000 at 3:28:16 PM.
visitors to this page.