I will like to list each member of an array listed with its corresponding register address location. Here is my code
// PointerDeferenceTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int x=0, y=0;
int *px, *py;
int number[15] = {-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9};
while (x<14)
{
px = &x;
py = number+x;
cout << x+1 << ", " << px << ", " << *px << ", " << py << ", " << *py << ", " << py++ << ", " << *(py++) << ", " << *(++py) << " \n";
++x;
}
return 0;
}
Running at 64 bits getting the following unexpected result
1, 000000D7532FF874, 0, 000000D7532FF904, -1, 000000D7532FF900, -3, -1
2, 000000D7532FF874, 1, 000000D7532FF908, 0, 000000D7532FF904, -2, 0
3, 000000D7532FF874, 2, 000000D7532FF90C, 1, 000000D7532FF908, -1, 1
4, 000000D7532FF874, 3, 000000D7532FF910, 2, 000000D7532FF90C, 0, 2
5, 000000D7532FF874, 4, 000000D7532FF914, 3, 000000D7532FF910, 1, 3
6, 000000D7532FF874, 5, 000000D7532FF918, 4, 000000D7532FF914, 2, 4
7, 000000D7532FF874, 6, 000000D7532FF91C, 5, 000000D7532FF918, 3, 5
8, 000000D7532FF874, 7, 000000D7532FF920, 6, 000000D7532FF91C, 4, 6
9, 000000D7532FF874, 8, 000000D7532FF924, 7, 000000D7532FF920, 5, 7
10, 000000D7532FF874, 9, 000000D7532FF928, 8, 000000D7532FF924, 6, 8
11, 000000D7532FF874, 10, 000000D7532FF92C, 9, 000000D7532FF928, 7, 9
12, 000000D7532FF874, 11, 000000D7532FF930, 0, 000000D7532FF92C, 8, 0
13, 000000D7532FF874, 12, 000000D7532FF934, -858993460, 000000D7532FF930, 9, -858993460
14, 000000D7532FF874, 13, 000000D7532FF938, -858993460, 000000D7532FF934, 0, -858993460
I cannot figure out what I am doing wrong. The 4th column (py) is starting to list the 4th item in the array. But the code is set to read the first (number[0]). I amusing W10 Visual studio community 2017 compile 64 bit
UPDATE 1: In response to PhoenixBlue comment. Amended the array sample to use different numbers.
UPDATE 2: This is my expected result
1, 000000D7532FF874, 0, 000000D7532FF904, -4, 000000D7532FF900, -3, -1
2, 000000D7532FF874, 1, 000000D7532FF908, -3, 000000D7532FF904, -2, 0
3, 000000D7532FF874, 2, 000000D7532FF90C, -2, 000000D7532FF908, -1, 1
4, 000000D7532FF874, 3, 000000D7532FF910, -1, 000000D7532FF90C, 0, 2
5, 000000D7532FF874, 4, 000000D7532FF914, 0, 000000D7532FF910, 1, 3
6, 000000D7532FF874, 5, 000000D7532FF918, 1, 000000D7532FF914, 2, 4
7, 000000D7532FF874, 6, 000000D7532FF91C, 2, 000000D7532FF918, 3, 5
8, 000000D7532FF874, 7, 000000D7532FF920, 3, 000000D7532FF91C, 4, 6
9, 000000D7532FF874, 8, 000000D7532FF924,4, 000000D7532FF920, 5, 7
10, 000000D7532FF874, 9, 000000D7532FF928, 5, 000000D7532FF924, 6, 8
11, 000000D7532FF874, 10, 000000D7532FF92C, 6, 000000D7532FF928, 7, 9
12, 000000D7532FF874, 11, 000000D7532FF930, 7, 000000D7532FF92C, 8, 0
13, 000000D7532FF874, 12, 000000D7532FF934, 8, 000000D7532FF930, 9, -858993460
14, 000000D7532FF874, 13, 000000D7532FF938, 9, 000000D7532FF934, 0, -858993460