关于sizeof的问题
来源:互联网 发布:事件营销诺一网络公关 编辑:程序博客网 时间:2024/05/22 05:27
假如是32位机
void Func ( char str[100])
{
请计算
sizeof( str ) = 4 (因为数组传给函数时自动转化成了指针)
}
char str[] = “Hello” ;
char *p = str ;
int n = 10;
请计算
sizeof (str ) = 6 (str是字符数组,加上“/0”一共6个字节)
sizeof ( p ) = 4 (p是指针,就是一个地址,32位机就是4个字节)
C++ primer里面写有“In most cases when we use an array, the array is automatically converted to a pointer to the first element;The exceptions when an array is not converted to a pointer are: as the operand of the address-of (&) operator or of sizeof, or when using the array to initialize a reference to the array.”
str使用sizeof后仍然是数组,不会转变成指针
sizeof (*p ) = 1(p为指向第一个元素的指针,*p就是字符H)
sizeof ( n ) = 4
void *p = malloc( 100 );
请计算
sizeof ( p ) = 4
类似的还有
short a[100];
short *b;
short (*c)[100];
short *d[100];
sizeof(a)=200 (100个short型数据,每个占两个字节)
sizeof(b)= 4
sizeof(c)= 4(c为指向一维数组的指针,这个一维数组有100个整型数据)
short *b;
short (*c)[100];
short *d[100];
sizeof(a)=200 (100个short型数据,每个占两个字节)
sizeof(b)= 4
sizeof(c)= 4(c为指向一维数组的指针,这个一维数组有100个整型数据)
sizeof(d)=400(指针数组,一共一百个,每个均指向整型数组)
- 关于sizeof的问题
- 关于sizeof的最大值问题
- 关于sizeof的细节问题
- 关于sizeof的误用问题
- 关于sizeof的相关问题
- 关于sizeof(str)的问题
- 关于sizeof注意的问题
- struct 关于sizeof的大小问题
- sizeof(struct)--关于字节对齐的问题
- QQ群里问的关于sizeof问题
- 关于求sizeof(struct)“不正确”的问题
- 关于struct调用sizeof的一个问题
- 关于sizeof的问题(1)
- 关于sizeof的问题(3)
- 关于sizeof(struct student)的问题
- 关于数组,sizeof(),strlen的计算问题
- sizeof和sizeof的问题
- 关于nest class 的构造问题 和 sizeof 问题
- c++中的引用的使用原理和使用实例 (1)
- 与 SNORT 相关的sth(2)--- 关于SNORT的安装
- 关于测试设计书的只言片语
- 在JBoss里配置MySql数据源
- 一条css语句让网站所有网页变黑白(灰色)
- 关于sizeof的问题
- 两个电话之间的SIP通话范例
- JBoss Hibernate 配置与应用
- 最基本的Socket编程C#
- 常用排序法
- 托普集团程序员面试题--转载
- 选择最适合自己的备份技术
- const char*, char const*, char*const的区别
- 计算机中进制的转换