Newbie Pointer question - An Arrays & and *
Hi,
With this code I am trying to cout the contents and memory location of the array's 'containers'.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int arrayz[5];
int *pointername;
pointername = arrayz;
for(int t = 0; t<5; t++)
{
int randomint = rand();
arrayz[t] = randomint;
cout << "Arrayz location " << t << "is " << &pointername[t] << " and value is " << *pointername << endl;
}
system("pause");
}
During de-bugging, I see random integers being placed into the array as I wanted, but as the screenshot shows below, the cout of the contents are being shown as the same every time.
This is confusing me, as I don't see why they aren't displayed as different, as I know they indeed are.
Any help is greatly appreciated.
Thanks.
EDIT - I have tried adding [t] to the end of *pointername in the cout line, but it fails to compile, but works with &pointername.