sizeof()运算符与strlen()函数的区别
来源:互联网 发布:linux测试网速 编辑:程序博客网 时间:2024/06/03 06:47
sizeof()运算符与strlen()函数的区别:
sizeof(),计算的是所占空间的大小;
strlen(),计算的是字符串的长度,到'\0'截止,不包括'\0';
以下用例子说明两者区别:
在32位系统下,
char str[] = “1234567890”;
char *p = str ;
char array[10] = {‘h’,’e’,’l’,’l’,’\0’,’o’};
sizeof (str ) = ?//值为11,字符串str中含有10个字符,系统会在数组的最后自动加一个'\0',所以字符串空间共占11个字节
sizeof ( p ) = ? //值为4,指针变量是用来存储地址的,所占空间的大小与定义的指针类型无关,只与CPU的寻址长度有关
sizeof ( array ) = ? //值为10,数组array分配的空间大小为10
strlen(array) = ? //值为4,计算数组array的长度,到'\0'截止,不包括'\0'
void Foo ( char str[100]){
sizeof(str) = ?//值为4,str代表数组str的首地址,在32位系统中所占空间是4字节。
}
void *p = malloc( 100 );
sizeof ( p ) = ? //值为4,p作为指针变量所占空间为4
0 0
- sizeof()运算符与strlen()函数的区别
- sizeof(...)运算符strlen(...)函数的区别与练习
- strlen与strcpy函数实现的浅谈及辨析sizeof运算符与strlen函数的区别
- sizeof运算符和strlen函数的区别
- sizeof运算符与求字符串长度函数strlen的区别
- strlen函数与sizeof的区别
- sizeof与strlen函数的区别
- sizeof与strlen函数的区别
- #define和inline的区别 sizeof与strlen的区别 以及运算符函数关键字三种概念
- strlen,wcslen,lstrlen函数与sizeof运算符
- strlen,wcslen,lstrlen函数与sizeof运算符
- strlen,wcslen,lstrlen函数与sizeof运算符
- strlen,wcslen,lstrlen函数与sizeof运算符
- strlen,wcslen,lstrlen函数与sizeof运算符
- sizeof与strlen的区别
- sizeof()与strlen()的区别
- sizeof 与 strlen 的区别
- sizeof与strlen的区别
- RequireJS笔记
- 将pdf转化成jpg图片有哪些方法
- html5表格元素
- Gradle使用技巧1——根据buildType自动打包
- 你真的了解android中的SAX解析吗?
- sizeof()运算符与strlen()函数的区别
- requestFocus标签的使用(为控件设置焦点)
- 自定义 Azure Table storage 查询过滤条件
- JavaEE程序猿之hello world ⑦
- Cannot merge new index 65553 into a non-jumbo instruction
- POJ 3311 - Hie with the Pie
- mongo数据库的备份与还原
- 前方高能!mysql巨坑之web程序传入中文参数查询无结果
- 二叉树