Hi,
But the array example works: the output is 1. My question is why? Why is the array example like assigning a simple type and not like assigning a class object? In the array example, it seems to me you are assigning a pointer to the outer variable which points to an address in memory which contains the array, and then the array goes out of scope, so why can you still access the array? Shouldn't it no longer exist?
Applying that to the array, shouldn't outerB's block of memory contain the address of the inner array?Variables are just blocks of memory that hold values. When you assigned outerA to i (outerA = i; ) the value in i's block was put into outerA's block. Once you get out of that if statement, i's block goes away, but the value is still stored in A's block. Same thing with outerB and the array.