Experiment 7: auto Scope, Part I


The Question: What happens if we declare the same name twice within a block, giving it two different meanings?

Hypothesis: Using your experience and intuition, construct a hypothesis.





Experiment 7: Add a declaration

   int main()
   {
      int arg1;
      arg1 = -1;
      ...
      char arg1 = 'A';
   }
just before the end of the main function. Since arg1 is declared near the beginning of the main function as the name of an int, redeclaring it as a char within the same block will answer our question.

Observation: Translate your source program. What is displayed ?





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






Back to the Lab Exercise

Forward to the Next Experiment


Copyright 1998 by Joel C. Adams. All rights reserved.