+ 3
Question about pointer and reference outputs
Why is the output to the following code 1021 and not 1121? int x= 10, y= 20; int *ptr = &x; int &ref = y; *ptr++; ref++; cout<<x<<y;
5 Antworten
+ 3
No, it was not right. It is due to operators priority. ptr is increased before reading.
Try (*ptr)++.
+ 2
Philip I wasn't right and corrected my answer.
+ 2
Thank you, Sergey Ushakov!
+ 1
Tind 😉