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; } }
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.
0
thanks