jeudi 10 juin 2021

What is the precedence order of postfix and prefix incremental operators? [duplicate]

According to the precedence table the precedence of postfix operator is higher than prefix operator, so the output of the following code should be 2 as first si++ is evaluated then ++si is incremented. So, the output should be 4-2 which is 2. But the actual output is 0. Can anyone explain why so?

#include <stdio.h>

int main()
{
    short int si = 2;
    short int a = ++si - si++;
    printf("%d ", a);

    return 0;
}

Output:

0

Aucun commentaire:

Enregistrer un commentaire