Either it's a trick question, or your teacher is wrong.
cout<<++*p<<*p++<<(*p)++<<*++p<<++*p++<<endl;
This does not have reliable output in any situation. According to the C++ standard, it's
undefined behavior. There's no way to reliably predict what the output will be. There is no "correct" output because the output is undefined. There's no way to answer this question.
The best answer you can give your teacher is "there is no answer because the code modifies a variable multiple times between sequence points, which results in undefined behavior according to the C++ language standard".
EDIT:
In case that doesn't satisfy your teacher, you can elaborate further and say:
"However, the below code:
1 2 3 4 5 6 7 8 9
|
int a[]={5,4,2,3,1};
int *p=a;
cout << ++*p;
cout << *p++;
cout << (*p)++;
cout << *++p;
cout << ++*p++;
cout << endl;
| |
outputs XXXXX, because <put your explanation here>"