Originally Posted by
Adak
But ++max IS trying to change a define, and defines are constant values.
#define's are not constant values. They are directions to the preprocessor to perform substitution of text in source code.
So
Code:
#define max 52
int main()
{
++max;
}
is effectively seen by the compiler - after completion of preprocessing - as
Code:
int main()
{
++52;
}
which (by attempting to increment a literal value, which is not permitted) causes a compilation error.
As to the original question, any change of a variable twice in one statement causes undefined behaviour. Anything is allowed to happen, including crashing your hard drive or producing the output that your teacher expects.
All the teacher is doing is assuming that the various increment operators are performed in some order. To give the explanation s/he seeks, simply find an order of operations that might explain the particular output.
However, your teacher is getting you to learn rubbish. Apart from the (hopefully remote) possibility of crashing your hard drive, the behaviour from that code is not predictable. The behaviour can change between versions of a compiler, change when you use another compiler, and all sorts of things.
EDIT: As to whether you tell the teacher that, it depends. Some (poor) teachers do not take kindly to being legitimately corrected. Some accept that in good grace. If your teacher is one who does not take kindly to being corrected, you might be better off saying nothing, and trying to learn C properly once you get past this class.