Looks like you're printing the address of p, not any value. Plus you never actually use x for anything. But if you tried to print x[2] you would probably get garbage since p isn't initialized.
You're using an uninitialized value. The value of p is undefined at the point when you put it into the array.
Also, when you print out &p, you are asking for the address where p lives, not the value stored in p. Nor, for that matter, are you asking about the contents of the array. (If x were changed, p wouldn't reflect those changes -- p was just used to fill the array in the first place, it has no further involvement in x.)
The address of an array element is not the same thing as its index. (You may find it interesting to print out the addresses of each successive element, and notice the pattern, and compare it to sizeof int).
#include <iostream>
usingnamespace std;
int main()
{
int p = 30;
int garbage[500]; // Ignore this.
int arr[] = {10, 20, p, 40, 50}; // Initialize an array, copying the value of p.
cout << "An int is: " << sizeof(int) << " bytes on this environment." << endl;
cout << "&p == " << &p << endl; // Print the address of p.
for(int i = 0; i < 5; i++) // Print the address of each array element.
cout << "&arr[" << i << "] == " << &arr[i] << endl;
cin.get();
}
When you look at the result, notice that: 1) p doesn't live anywhere in the array, and 2) the array elements' addresses are evenly spaced. If an int takes 4 bytes, then the first 4 bytes of the array are the first int, and the next 4 bytes are the next, etc. etc.