I have a pointer to array, why it gives me the following output?
int main() {
int b[] = {1, 2};
cout << "size of int = " << sizeof(int) << endl;
int *pt = b;
int i = 0;
while( i++ < 2) {
cout << "pt = " << pt << ", b = " << b << endl;
cout << pt - b << endl;
(pt)++;
}
return 0;
}
code output:
size of int = 4
pt = 0x7fff576f0c2c, b = 0x7fff576f0c2c
0
pt = 0x7fff576f0c30, b = 0x7fff576f0c2c
1
pt is a pointer to the start of array b initially, why pt-b gives me the index of the array that pt points to rather than the index of the array times the size of one element.