And again I am not so sure if what a tutor at my university is telling us about C is actually true.
Today, he gave us an example of a valid (?) C expression:
i+++++i---i
Then he used some brackets to make this expression easier to read:
(i++)+(++i)-(--i)
So, I did write a small program to explore how my compiler (Borland C++ Command Line Tools 5.5.1) would handle this:
These are the error messages thrown at me by the compiler:Code:#include <stdio.h> int main() { int a, i = 5; a = i+++++i---i; printf("%d", a); return 0; }
Error E2277 test18.c 8: Lvalue required in function main
Warning W8004 test18.c 12: 'i' is assigned a value that is never used in function main
I've already looked into the ANSI C Standard and found out that the order in which the post-/prefix operations are executed is undefined. It is only defined that they must be carried out between the ';' of the previous expression and the ';' at the end of the current expression.
Now, my question: Why does the compiler give the error messages above? And why does the program "work" if I put the expression in brackets (as shown above) - although the output of the program is the value I've initialized int i with and the compiler still gives the warning message(as shown above) but no more error message.
Thank you for your help.