c 顺序点

prinf() 和&&,注意printf("%d\n", a1)

#include "stdio.h"

int main(int argc, char const *argv[])
{
    
    int a1=3;
    int b1=++a1&&printf("%d\n", a1);
    printf("%d\n", b1);
    printf("%s\n", "......................");

    int a2=5;
    int b2=++a2&&printf("%d\n", a2);
    printf("%d\n", b2);
    printf("%s\n", "......................");

    int a3=7;
    int b3=a3++&&printf("%d\n", a3);
    printf("%d\n", b3);
    printf("%s\n", "......................");

    int a4=9;
    int b4=a4++&&printf("%d\n", a4);
    printf("%d\n", b4);
    printf("%s\n", "......................");

    return 0;
}

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
4
1
......................
6
1
......................
8
1
......................
10
1
......................
[Finished in 0.1s]

printf()和&

#include "stdio.h"

int main(int argc, char const *argv[])
{
    
    int a1=3;
    int b1=++a1&printf("%d\n", a1);
    printf("%d\n", b1);
    printf("%s\n", "......................");

    int a2=5;
    int b2=++a2&printf("%d\n", a2);
    printf("%d\n", b2);
    printf("%s\n", "......................");

    int a3=7;
    int b3=a3++&printf("%d\n", a3);
    printf("%d\n", b3);
    printf("%s\n", "......................");

    int a4=9;
    int b4=a4++&printf("%d\n", a4);
    printf("%d\n", b4);
    printf("%s\n", "......................");

    return 0;
}

4
0
......................
6
2
......................
8
2
......................
10
1
......................
[Finished in 0.1s]

printf()和&

#include "stdio.h"

int main(int argc, char const *argv[])
{
    
    int a1=3;
    int b1=++a1&printf("%d", a1);
    printf(" %d\n", b1);
    printf("%s\n", "......................");

    int a2=5;
    int b2=++a2&printf("%d", a2);
    printf(" %d\n", b2);
    printf("%s\n", "......................");

    int a3=7;
    int b3=a3++&printf("%d", a3);
    printf(" %d\n", b3);
    printf("%s\n", "......................");

    int a4=9;
    int b4=a4++&printf("%d", a4);
    printf(" %d\n", b4);
    printf("%s\n", "......................");

    return 0;
}

4 0
......................
6 0
......................
8 1
......................
10 0
......................


printf()和&&

#include "stdio.h"

int main(int argc, char const *argv[])
{
    
    int a1=3;
    int b1=++a1&&printf("%d", a1);
    printf(" %d\n", b1);
    printf("%s\n", "......................");

    int a2=5;
    int b2=++a2&&printf("%d", a2);
    printf(" %d\n", b2);
    printf("%s\n", "......................");

    int a3=7;
    int b3=a3++&&printf("%d", a3);
    printf(" %d\n", b3);
    printf("%s\n", "......................");

    int a4=9;
    int b4=a4++&&printf("%d", a4);
    printf(" %d\n", b4);
    printf("%s\n", "......................");

    return 0;
}

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
4 1
......................
6 1
......................
8 1
......................
10 1
......................
[Finished in 0.1s]

注:关于顺序点,可以参考http://blog.sina.com.cn/s/blog_60281b700100dcmg.html

你可能感兴趣的:(c 顺序点)