考试酷解析——A3_Constants

解析

第三题:

//For the following code snippet:
char *str = "Sanfoundry.com\0" "training classes";
//The character pointer str holds reference to string:

'\0'被看作是一个字符,在计算字符串长度的时候只会记到Sanfoundary.com,但是在输出的时候还是会输出Sanfoundry.com\0training classes

第八题:

//What is the output of this C code?
#include 
#include 
int main()
{
char *str = "x";
char c = 'x';
char ary[1];
ary[0] = c;
printf("%d %d", strlen(str), strlen(ary));
return 0;
}

str只有一个字符,所以长度是1;而ary没有填满,所以长度是任意的,undefined value

 

你可能感兴趣的:(C语言考试酷)