设为首页 加入收藏

TOP

C语言需要注意的问题
2014-11-24 07:17:42 来源: 作者: 【 】 浏览:1
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的使用方法

评论

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

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)