Search code examples
subtractiondecrement

decrement operator vs subtraction operator


If I write a code like(in c)

    x=1;
    z=2;
    y=x---z;

will first two - be treated as post-decrement and later one as subtraction

or first - will be treated as subtraction and other two as pre-decrement

and what if I put a space to make it the other (because in c program doesn't change by white space)


Solution

  • As per the C11 standard, chapter §6.4 , lexical elements, (emphasis mine)

    If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token. [..]

    So,

    y=x---z;
    

    is

    y= (x--) - z;
    

    This is also called as Maximal munch rule.