The book I am studying from makes the following two statements:
1. The array name (without a subscript) is a (constant) pointer to the first element of the array.
2. The name of an array is actually the address in memory of the first element of the array.
When I run the following program:
I get the following result:
I don't understand why the lines in red above produce the same output. I understand why b = 0023FEAC but why does &b = 0023FEAC ? If my understanding of pointers is correct, it seems like it is a pointer pointing to itself.
1. The array name (without a subscript) is a (constant) pointer to the first element of the array.
2. The name of an array is actually the address in memory of the first element of the array.
When I run the following program:
Rich (BB code):
#include <iostream>
using namespace std;
int main()
{
int b[5] = {11, 22, 33, 44, 55};
const int *bPtr = b;
//Part 1
cout << "Part 1" << endl;
cout << "b = " << b << endl;
cout << "&b = " << &b << endl;
cout << "*b = " << *b << endl;
cout << endl;
//Part 2
cout << "Part 2" << endl;
cout << "bPtr = " << bPtr << endl;
cout << "&bPtr = " << &bPtr << endl;
cout << "*bPtr = " << *bPtr << endl;
return 0;
}
Rich (BB code):
Part 1
b = 0023FEAC
&b = 0023FEAC
*b = 11
Part 2
bPtr = 0023FEAC
&bPtr = 0023FEA8
*bPtr = 11
Press any key to continue . . .