another quick pointer question

hey people just have another quick pointer question when I assign a pointer to an array with the first line of code does this create a pointer to the size for the array in other words is it just one pointer that points to the first address of the array or is it an array of pointers with each array pointer pointing to each element of the array?

thanks in advance,

Adam

1
2
3
4
  int *ray = new int[3];
    ray[0] = 4;
    ray[1] = 5;
    ray[2] = 6;
the pointer points to the first element of the array
Hi,
A pointer acts like an one-dimension array.
1
2
3
4
5
6
7
8
int foo[3] = {3, 9, 27};

int *ptr;
ptr = foo; // store the memory address of foo

cout << ptr[0] << '\n'; 
cout << ptr[1] << '\n'; 
cout << ptr[2] << '\n'; 


Pointers are specialized in storing the memory addresses of other variables. And unlike arrays, pointers are more flexible you can make them point to different variables of your choices. You can also perform some certain arithmetical operations (e.g : '+', '-', '+=', '-=') when you operate with pointers.
TheIdeasMan wrote:
Just a note for the future :+)

There also shouldn't be 2 topics about essentially the same subject. There is a risk that the same things will be said in both, possibly making it a time waster for those who reply.
thanks guys
You are welcome :)
Topic archived. No new replies allowed.