Pointers, confusing little monsters

Why does a pointer to this memory location always have the same address? Shouldn't a different array number have a different pointer address or is an array simply a feature of the language alone?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include <iostream>
using namespace std;

int main()
{
int A[100], *B, i=0;
while (i<10)
{
	i++;
A[i]=100;
B=&A[i];
cout<<&B<<endl;
}
}
> Why does a pointer to this memory location always have the same address?

The process address space layout is not randomised.
https://en.wikipedia.org/wiki/Address_space_layout_randomization
Your not printing the address of the array elements. Your printing the address of the pointer itself.
As Yanson said, line 12 should be cout << B << endl;
Topic archived. No new replies allowed.