Out of Scope?
Posted: Wed Nov 26, 2008 9:25 pm
Well I was reading my Sams Teach Yourself C++ in an Hour a Day and one of the questions asked this:
What is the value of x when the for loop completes?
I thought it would be 100, because the first statement it defines and initializes the variable, so I would think it should be 100.
The answer in the book says: "The variable is out of scope and thus has no valid value"
I'm a little confused by this. Is this just meaning after the for loop completely ends? or the final value of x?
My best guess is the variable was created within the loop so once the loop ends, its out of scope, and the question is referring to after the loop ends.
What is the value of x when the for loop completes?
Code: Select all
for (int x = 0; x < 100; x++)
The answer in the book says: "The variable is out of scope and thus has no valid value"
I'm a little confused by this. Is this just meaning after the for loop completely ends? or the final value of x?
My best guess is the variable was created within the loop so once the loop ends, its out of scope, and the question is referring to after the loop ends.