char *p[2][3];
How does *(*(p+1)+1)[7] equal p[1][8][0]?
I thought *(*(p+1)+1)[7] would be the same as *(*(*(p+1)+1)+7) and that is equal to p[1][1][7], where am I wrong?
E: I don't understand why this is being downvoted...
Basic facts:
[] associates left to right[] has higher precedence than the dereference operator *a[i] is *(a+i)So
*(*(p+1)+1)[7]
= *((*(p+1)+1)[7]) // rule 2
= *(*(*(p+1)+1+7)) // rule 3
= *(*(*(p+1)+8))
= *(*(*(p+1)+8)+0)
= p[1][8][0] // rules 1 and 3
This depends on the relative precedence of [] vs unary * (the former is higher), and the essential identity that if p is (or evaluates to) a pointer and n is of integer type then p[n] means the same thing as *(p + n). You can therefore transform your starting expression according to the following steps, making repeated use, in both directions, of that identity:
*(*(p+1)+1)[7]*((*(p+1)+1)[7]) (The added parentheses express the operator precedence explicitly.)*((p[1]+1)[7])*(*((p[1]+1)+7))*(*(p[1]+1+7))*(*(p[1]+8))*(p[1][8])*(p[1][8] + 0)p[1][8][0]If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With