设为首页 加入收藏

TOP

C语言需要注意的问题
2014-11-24 07:17:42 来源: 作者: 【 】 浏览:0
Tags:语言 需要 注意 问题

1、*p++,*++p,*(p++),*(++p)

这四种书写不等价

/*********test p *******/
int _tmain(int argc, _TCHAR* argv[])
{
int b
int a[]={1,2,3};
int *p;
p=&a[1];
b=*++p;
printf("current p is %x\ncurrent *p is %d\nb is %d",p,*p,b);
return 0;
}


/*****************/

2、sizeof与strlen的区别

sizeof是运算符

strlen是函数,在驱动开发中不可用

/*********test strlen()*******/
int _tmain(int argc, _TCHAR* argv[])
{
char s[]="abcdef";
int i=strlen(s);
int j=sizeof(s);
char c[]={'a','b','c','d','e','f'};
int m=strlen(c);
int n=sizeof(c);
printf("current i is %d\ncurrent j is %d\n",i,j);
printf("current m is %d\ncurrent n is %d\n",m,n);
return 0;
}
/*****************/

sizeof把'\0'包括在内

但是strlen却不包括,只有遇到时,才终止。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android调用系统联系人返回联系人.. 下一篇RCFileInputFormat的使用方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)