coperator-precedenceevaluationassociativity

What is the difference between order of precedence and order of evaluation in C?


I have a specific example in mind.

x = a +++ b;

This is evaluated as a++ not ++b. But I don't understand if this is due to order of precedence of postfix being higher than prefix, or due to order of evaluation being right-to-left.

What is the difference between these two terms?


Solution

  • The C and C++ compilers process tokens eagerly and will split the expression based on the longest possible valid tokens it can find. It is defined by C standard

    C11 Standard, Section 6.4, Paragraph 4

    If a ‘token’ can be formed by concatenating characters to form a valid keyword, identifier, constant, string literal, punctuator, or other character, then the largest possible ‘token’ should be selected.