Output question (this question was asked in instagram post of coding blocks)

int main()
{
int arr[]={10,20};
int *p=arr;
(p++)++;
cout<<ar[0]<<" “<<1[arr]<<” "<<
–p;
return 0;
}

in cpp, arr[i] is resolved as *(arr+i). where arr is base address of array.
now arr[i] = i[arr] = *(arr+i)… same thing.
(p++)++ is syntactically incorrect.
it should be p++; p++; and then
p is incremented twice and decremented once, so it will point to second element of array.
–p will print address of second element.

thanks

That was the wrong question
can u please explain this

aa[i] and i[arr] are same as explained.
(*p++)++ can be rewritten as
(*p++); => *p = *p+1 =. it means , arr[0] =11, since p is pointing to arr[0]
p++; => p start pointing to arr[1]

cout<<*–p; => this is *(–p) by associativity. p will point to arr[0] again and thus print 11.

these kind of questions are mainly bases on operator precedence and associativity.
thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Thanks for the help , but I always get confused in question regarding output .
Could you please help me with some learning resources and practice Questions .

For example in this question , What will be associativity and precedence ?