Well, remember that arrays can be interpreted as pointers
int arr[3]={10,20,30}; int *arrp = new int;
creates an arr array of three integers and an int pointer , which is assigned a fresh highlighted value.
Because assignment operators return a reference to the value that was assigned to enable multitasking,
(*(arr+1)+=3)+=5;
equivalently
*(arr+1)+=3; *(arr+1)+=5;
*(arr + 1) refers to the first element of the arr array, so arr[1] effectively increased by eight.
(arrp=&arr[0])++; assigns the address of the first element of the arrp array and then increments this pointer, which now points to the second element ( arr[1] again).
By dereferencing it in std::cout<<*arrp , you output arr[1] , which now contains the value 20 + 3 + 5 = 28 .
Thus, the code prints 28 (and also creates a memory leak, since the new int originally assigned to arrp never gets delete d)
Dario
source share