+ 4
Doubt regarding 'Pointer to Pointer & Pointer to Array' in C++
Please help me understand the mechanism of this program code about how it's generating the output, (-1). https://code.sololearn.com/c1Hg92zOoYE8/?ref=app
3 Answers
+ 10
int t[4]= {8, 4, 2, 1};
*p1 = t + 2 // p1 points to t[2]
*p2 = p1 - 1 // p2 points to t[1]
++p1 // p1 points to t[3]
*p1 - t[p1 - p2];
// 1-2
// -1
https://www.tutorialspoint.com/cprogramming/c_pointer_arithmetic.htm
+ 1
Could you please tell me how is p1 - p2 = 2 (in the 4th comment). That's where exactly I was facing the problem.
0
Okay, got it now after a closer dive. đ
Thanks! :)