C语言中sizeof()求字节数的应用举例

sizeof(char)=1
 sizeof(short)=2
 sizeof(int)=4
 sizeof(long)=4
 sizeof(float)=4
 sizeof(double)=8
 sizeof(long double)=8
 
sizeof(unsigned char)=1
 sizeof(unsigned short)=2
 sizeof(unsigned int)=4
 sizeof(unsigned long)=4
 sizeof(unsigned float)=4
 sizeof(unsigned double)=4
 sizeof(unsigned long double)=8
 

char a[] = {'a','b','c','d','e'};//sizeof(a)=5
 char b[] = "abcde";//sizeof(b)=6
 char c[][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'}};
 //sizeof(c)=12
 //sizeof(c[0])=3
 //sizeof(c[0][0])=1
 char d[][5] = {"abcc","deff","ghii","jkll"};
 //sizeof(d)=20
 //sizeof(d[0])=5
 //sizeof(d[0][0])=1
 char *p = 0;//sizeof(p)=4
 char *q = (char *)malloc(5);//sizeof(q)=4
 char *r = "abcde";//sizeof(r)=4
 char (*f)(void) = NULL;//sizeof(f)=4
 
char *s1[3] = {"aa","bb","cc"};
 //sizeof(s1)=12
 //sizeof(s1[0])=4
 //sizeof(*s1[0])=1
 
char *s2[3][3] = {{"aa","bb","cc"},{"aa","bb","cc"},{"aa","bb","cc"}};
 //sizeof(s2)=36
 //sizeof(s2[0])=12
 //sizeof(*s2[0])=4
 
char h[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
 char (*ph)[3] = h;
 //sizeof(ph)=4
//sizeof(*ph)=3
 //sizeof(ph[0])=3
 //sizeof(*ph[0])=1

C++ Primer Plus 第6版 中文版 清晰有书签PDF+源代码

读C++ Primer 之构造函数陷阱

读C++ Primer 之智能指针

读C++ Primer 之句柄类

C语言梳理一下,分布在以下10个章节中:

Linux-C成长之路(一):Linux下C编程概要

Linux-C成长之路(二):基本数据类型

Linux-C成长之路(三):基本IO函数操作

Linux-C成长之路(四):运算符

Linux-C成长之路(五):控制流

Linux-C成长之路(六):函数要义

Linux-C成长之路(七):数组与指针

Linux-C成长之路(八):存储类,动态内存

Linux-C成长之路(九):复合数据类型

Linux-C成长之路(十):其他高级议题

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c40fcd4f45cdd1fff4c4316b9c4ca093.html