奇怪++操作

weixin_34391854發表於2015-07-18

#include <stdio.h>

int main(void)
{
    int j, i = 3;

    printf("j = %d\n", j = (++i) + (++i) + (++i));

    i = 3;
    printf("j = %d\n", j = (i++) + (i++) + (i++));
    i = 3;
    printf("j = %d\n", j = (++i) + (i++) + (++i));

    return 0;
}

/*
   結果:
 * j = 16
 * j = 9
 * j = 13
 * */



#include <stdio.h>

#define SQUARE(x) ((x)*(x))
int main(void)
{
    int a = 5;
    int b, c;
   
    b = SQUARE(a++);
    a = 5;
    c = SQUARE(++a);
    
    printf("b: %d, c: %d\n", b, c);

    a = 5;
    b = (a++)*(a++);
    a = 5;
    c = (++a)*(++a);

    printf("b: %d, c: %d\n", b, c);

    a = 5;
    b = (a++)*(a++)*(a++);
    a = 5;
    c = (++a)*(++a)*(++a);

    printf("b: %d, c: %d\n", b, c);

    a = 5;
    b = (a++)*(a++)*(++a);
    a = 5;
    c = (++a)*(a++)*(++a);
    // 6*6*7 ?

?

? a = 5; c = (++a)*(a++); // 6*6 ??

?

printf("b: %d, c: %d\n", b, c); return 0; }


執行結果:

b: 25, c: 49
b: 25, c: 49
b: 125, c: 392
b: 150, c: 36


++ 什麼是法律表示式求值?

反編譯它?

版權宣告:本文部落格原創文章。部落格,未經同意,不得轉載。

相關文章