C的结构体使用
C的结构体演示
#include <stdio.h> struct A //建立结构体A { char *name; int s1; struct A *next; }; void main() { struct A a = { "啊一", 10 };//建立结构体对象 struct A b = { "啊二", 20 }; struct A c = { "啊三", 30 }; struct A *p; //建立结构体指针 p = &a; a.next = &b; //把b对象的地址给予a对象的指针 b.next = &c; c.next = NULL; while (1) //输出循环体 { printf("%s,%d\n", p->name, p->s1); if (p->next == 0) { break; } p = p->next; } system("pause"); }