Array and pointer problemsssss

#include<iostream>
int main(){
int digits[10]={1,2,3,4,5,6,7,8,9,10};
int *p1=digits;
int *p2=digits+9;

I would like to know why *p1=1.
Isn't digits include all 1 to 10?? thanksss
int *p1=digits; is the same as int *p1 = &digits[0];.

p1 points to the first element in the array.
p2 points to the tenth element in the array.
@Peter87
Thanksssssss. It really helps. :D
you can also increment pointers,since pointer p1 is an int it is 4 bytes(on most systems) long so by incrementing pi you will move it to the next int,so p1 now points to the next four bytes in memory

1
2
3
4
5

  cout << *p1 << endl; // prints 1;
  p1++;
  cout << *p1 << endl; // should now print 2
Last edited on
Topic archived. No new replies allowed.