标签:
● 数 组:只能由多个相同类型的数据组成
● 结构体:可以由多种不同类型的数据组成
代码练习:
#include <stdio.h> int main() {
// 1.定义结构体类型 struct person (并不会分配存储空间)
struct person { int age; double height; char *name; }; //2.根据结构体类型,定义结构体变量 (真正分配存储空间)
struct person p ={20,1.55,"jack"}; p.age = 30; //修改结构体元素的值 p.name = "rose"; printf("age =%d,name = %s,height = %f\n",p.age,p.height,p.name); return 0; }
int main() { struct student { int age; double height; char *name; }; struct student stu = {20,1.78,"jack"}; }
int main() { struct student { int age; double height; char *name; }stu; struct student stu2; }
int main() { struct { int age; char *name; }stu; }
标签:
原文地址:http://www.cnblogs.com/shtz/p/4423702.html