I ++ and C language macro definition demo

Today saw a very strange feature, they note down

Code:

#include <stdio.h>
#include <string.h>

#define SQ(y) ((y)*(y))
int main(){
    int i=1;
    while(i<=5){
        printf("%d^2 = %d\n", i, SQ(i++));
        fflush(stdout);
    }

    return 0;
}

This is, I always thought the first line of output: 1 ^ 2 = 1, i always thought that the value of the next cycle ++ is used, the results did not expect

On the right: SQ (i ++ ) = ((i ++) * (i ++)) = "1 * 2 = 3 
to the left of: i = 3 (pay special attention to this place !!! 1 !!! I always thought I did not expect two consecutive times the value of i after i ++ into a 3!)

 Similarly available, one more i ++

 

Guess you like

Origin www.cnblogs.com/bbllw/p/12469359.html