我试图理解下面的一段代码,但我对 "\0"
和 '\0'
感到困惑。我知道这很愚蠢,但请帮助我出
#define MAX_HISTORY 20
char *pStr = "\0";
for(x=0;x<MAX_HISTORY;x++){
str_temp = (char *)malloc((strlen(pStr)+1)*sizeof(char));
if (str_temp=='\0'){
return 1;
}
memset(str_temp, '\0', strlen(pStr) );
strcpy(str_temp, pStr);
最佳答案
它们是不同的。
"\0"
是一个字符串文字,它有两个连续的 0,大致等同于:
const char a[2] = { '\0', '\0' };
'\0'
是一个值为 0 的 int
。您可以在需要使用 '\0'
的任何地方始终为 0。
关于c - "\0"和 '\0' 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40129319/