I was just playing around with some code when I ran into this.
The output for this code was 7, 1, 2686728, 9, 7, 5, 3, 1
(if you run this your third number may be different)
In the code I get an address when cout is executed the third time note (anArray - 1). "I thought it would print (anArray) one element below the last one but I was wrong" Is this the address the actual address of element [3] or the address one byte below it or what?
How can I prove what it is??
Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
int anArray[5] = { 9, 7, 5, 3, 1 };
cout << *(anArray+1) << endl;
cout << * (anArray +4) <<endl;
cout << *(anArray -1) <<endl;
cout << anArray [0]<<endl;
cout << anArray [1] <<endl;
cout << anArray [2] <<endl;
cout << anArray [3] <<endl;
cout << anArray [4] <<endl;
return 0;
}