标签:c 结构体 printf 变量 结构 void span 存储空间 struct lis
C 数组允许定义可存储相同类型数据项的变量,结构是 C 编程中另一种用户自定义的可用的数据类型,它允许您存储不同类型的数据项。
#include<stdio.h> #include<malloc.h> struct Company{ int peopleNum; char *name; char *address; }company; void printCompany(struct Company *c); int main(){ struct Company c; c.name=malloc(100); c.name="lisi"; c.address=malloc(1000); c.address="chaoyangmen"; c.peopleNum=100; printCompany(&c); } void printCompany(struct Company *company){ printf("%d\n",company->peopleNum); printf("%s\n",company->name); printf("%s\n",company->address); }
结构的储存空间
#include<stdio.h> struct tp1{ char a; char b; int c; }tpp1; struct tp2{ char a; int c; char b; }tpp2; int main(){ printf("%d\n",sizeof(tpp1)); printf("%d\n",sizeof(tpp2)); }
输出结果是
8
12
原因是:结构体占用存储空间,以32位机为例
标签:c 结构体 printf 变量 结构 void span 存储空间 struct lis
原文地址:http://www.cnblogs.com/blueberry006/p/7701209.html