歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> C語言需要注意的問題

C語言需要注意的問題

日期:2017/3/1 9:57:19   编辑:Linux編程

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卻不包括,只有遇到時,才終止。

Copyright © Linux教程網 All Rights Reserved