#include <stdio.h> #include <stdlib.h> struct info { int num; float score; }; int main() { struct info info1; printf("%d %f",info1.num = 10, info1.score = 29); struct info *p1 = &info1; printf("\n%d %f",(*p1).num,(*p1).score); printf("\n%d %f",p1->num,p1->score); //完全等价 struct info *p2 = (struct info*)malloc(sizeof(struct info)*5); int i = 0; for(struct info *px = p2; px < p2+5; px++) { px->num = i; px->score = i+3.5; i++; printf("\n%d,%.2f",px->num,px->score); } return 0; }
原文地址:http://blog.csdn.net/huolang_vip/article/details/43655391