加入收藏 | 设为首页 | 会员中心 | 我要投稿 开发网_开封站长网 (http://www.0378zz.com/)- 科技、AI行业应用、媒体智能、低代码、办公协同!
当前位置: 首页 > 教程 > 正文

C语言需要谨慎的问题

发布时间:2021-11-21 17:32:02 所属栏目:教程 来源:互联网
导读: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 %xncurrent *p is %dnb is %d,p,*p,b); return 0; } /*********
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 %xncurrent *p is %dnb 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 %dncurrent j is %dn",i,j);
  printf("current m is %dncurrent n is %dn",m,n);
  return 0;
 }
 /*****************/
 
sizeof把''包括在内
 
但是strlen却不包括,只有遇到时,才终止。

(编辑:开发网_开封站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读