sizeof
2015-10-23 23:00
260 查看
#include<stdio.h> int main() { struct Test { int a[3]; char b; short c; }; typedef struct Test test2; struct Test test={{2,4},88,3}; struct Test test1; printf("%d",sizeof(test2)); printf("%d",sizeof(test)); printf("%d",sizeof(test1)); }
(1) Test只是一个标志,struct Test才是一个类型,因此printf("%d",sizeof(Test))不对。同时sizeof是求的变量或类型。因此3个输出都是16.
(2)对结构体struct Test test={{2,4},88,3};的初始化清楚
由结构想到枚举。
#include<stdio.h>
void main()
{
enum spectrum {red,green,blue,hot,yellow};
enum spectrum color;
printf("%d\n",color);
color=2;
printf("%d\n",color);
color=yellow;
printf("%d\n",color);
color=7;
printf("%d\n",color);
//printf("%d\n",color.red);
printf("%d\n",red);
//printf("%d\n",color.red);
//red=3;
printf("%d\n",red);
printf("%d",sizeof(enum spectrum));
//printf("%d",sizeof(spectrum));
}输出为1 2 4 7 0 0 4
其中的spectrum为标志 ,enum spectrum才是类型,枚举不是结构,不能用color.red.
enum spectrum {red,green,blue,hot,yellow};中的red green 为常量可以直接输出
谷歌
相关文章推荐
- 你所不知道的事儿--C++中delete指针后最好赋值为NULL
- MSF终端命令
- LiteHttp 第一节:初始化和初步使用
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
- Javascript计数器
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
- 【翻译】Ext JS最新技巧――2015-10-21
- 借助 SublimeLinter 编写高质量的 JavaScript & CSS 代码
- POJ2186 (强连通分量缩点后出度为0的分量内点个数)
- 九度OJ 1118:数制转换 (进制转换)
- LPC43xx SGPIO Pattern Match Mode
- ogg实现oracle到sql server 2005的同步
- appium for hybrid app 处理webview
- 九度OJ 1118:数制转换 (进制转换)
- 【鸟哥的linux私房菜-学习笔记】首次使用相关知识、在线求助 man page
- 剑指Offer--二叉树的深度
- 【翻译】Ext JS最新技巧——2015-10-21
- C#winform窗体用户控件自定义事件
- 【翻译】Ext JS最新技巧——2015-10-21
- 九度OJ 1117:整数奇偶排序 (排序)