[C]结构数组,++p->x 与 ++(p->x)的优先级

 

 

#include <stdio.h>
typedef struct {
    long num;
    char name[10];
    double score;
} Stu;
int main() {
    Stu stu[3] = {20115602l, "Jerry", 99.5, 20115600l, "Elaine", 94.5, 20115607, "Kramer", 78}, *p = stu;
    int i;
    for (i = 0; i < 3; ++i, p++) {
        if (p->score >= 90)
            printf("%10ld%10s%6.1f\n", p->num, p->name, p->score);
    }
    return 0;
}

 

 

//++p->x 与++(p->x)相同

(++p)->x

#include <stdio.h>
typedef struct {
    int x, *y;
} link;
int main() {
    int a[4] = {100, 20, 25, 30};
    link scores[] = {10, &a[0], 15, &a[1], 16, &a[2], 17, &a[3]};
    link *p = scores;
    printf("%d\n", ++p->x); //11
    printf("%d\n", (++p)->x); //15
    printf("%d\n", ++(p->x)); //16
    return 0;
}

 

posted @ 2020-06-29 16:47  profesor  阅读(573)  评论(0编辑  收藏  举报