+ 1
Please explain how last line of this code is giving output ?
2 Answers
+ 1
10+2=12
int a[] = {0,1,-1,10,11} ;
int *p = a ;
initially p points to first location of array a by
int p = a; that is *p = 0
next p = p+3 cause pointer to forward 4th (index 3) element and *p = 10.
so *p+2 returns => 10+2 = 12
0
G'day Abhay mishra nice code.
Would you like a few pointer challenges?
What about using a pointer to access a 2d char array, maybe days of the week?
I still do that the long way: {my psuedocode}
Create array
Make a loop
Use loop counter to multiply the pointer return, eg *(p+ i*arr2dSize)