C语言 13 结构体数组

admin 2018年5月13日02:37:43评论508 views字数 647阅读2分9秒阅读模式
摘要

格式 :结构体 stStudent 的宽度为 8 + 32 = 40
我们观察到 结构体数组在内存中是连续存储的


结构体数组的定义

类型 变量名[常量表达式];  //定义结构体类型  struct stStudent {     int Age;     int Level; }  //定义结构体变量 struct stStudent st;  //定义结构体数组 struct stStudent arr[10]; //或者 stStudent arr[10];

结构体数组初始化

struct stStudent{     int Age;     int Level; };  struct stStudent arr[5] = {{0,0},{1,1},{2,2},{3,3},{4,4}};  //或者  arr[0].Age=100; arr[0].Level=100;

结构体成员的使用

格式 :

结构体数组名[下标].成员名  arr[0].Age = 10;

字符串成员的处理

struct stStudent{     int Age;     char Name[0x20]; } struct stStudent arr[3] = {{0,"张三"},{1,"李四"},{2,"王五"}};  //读 char buffer[0x20]; strcpy(buffer,arr[0].Name);  //写 strcpy(arr[0].Name,"王钢蛋");

结构体数组的内存结构

struct stStudent{     int Age;     char Name[0x20]; } struct stStudent arr[3] = {{0,"张三"},{1,"李四"},{2,"王五"}};  int x = arr[0].Age;

C语言 13 结构体数组

结构体 stStudent 的宽度为 8 + 32 = 40
我们观察到 结构体数组在内存中是连续存储的

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2018年5月13日02:37:43
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   C语言 13 结构体数组http://cn-sec.com/archives/51489.html

发表评论

匿名网友 填写信息