I can't wrap my head around this one. Can you guys simplify this concept for me so I can understand easier? What would the output here be? I tried running this code and I get 5197373. But my answer choices are:
a. Five memory addresses
I instinctively thought my answer was going to be the address of the numbers element, but that's not an option. What am I not understanding here?
1 2 3 4
int *numbers = newint;
for (int i=0; i <=4; i++)
*(numbers+1) = i;
cout << numbers << endl;
In the loop numbers ( numbers + 1 )is assigned i. As the last value of i is equal to 4 then numbers will be equal to 4. However after the loop you are displying numbers that was not assigned any value. So an arbitrary value is displayed.
So basically this loop is ONLY manipulating the numbers element as it iterates. The cout statement is not affected by the loop at all. Now if I were to change it to this below, then my output would be 4. Is that correct?