0

can someone please explain why output is 00000, not 01234 ?

int main() { int a[5]; int*p=a; for(int i=0;i<5;i++) { a[i]=i; cout<<*p; } }

7th May 2019, 4:17 PM
San Anemos
San Anemos - avatar
2 Answers
+ 5
Because the pointer p always points to the first element of the array (which happens to be zero). The pointer is not incremented. It is right that the array contains 0,1,2,3,4 after looping but the array is not printed here, only the (dereferenced) pointer.
7th May 2019, 4:31 PM
Thoq!
Thoq! - avatar
0
thanks
7th May 2019, 6:40 PM
San Anemos
San Anemos - avatar