0 ‘与‘\0’、 ‘0’
#include "stdafx.h" #include "string.h" #include "iostream" int _tmain(int argc, _TCHAR* argv[]) { char x[]="STRING";//系统认为是char x[7]; char y[]="0\00ING";//写在字符串中的是‘0’ \00当成八进制处理为对应的ASCII码对应的字符 所以系统认为是char y[6]; 这两个字符串系统都加了‘\0’ x[0]=0;x[1]='\0';x[2]='0';x[0]是整数零 ,相当于ASCII码 所以对应为‘\0’ printf("%d %d\n",sizeof(x),strlen(x)); printf("%d %d\n",sizeof(y),strlen(y)); system("pause"); return 0; }
所以结果为:
7 0
6 1