9.Which expression in following statements is not correct?( )A.char str[10]; str="string";B.char str[ ]="string";C.char *p="string";D.char *p; p="string";请说明原因谢谢12.Which is the output result of the following program code(
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 10:40:56
9.Which expression in following statements is not correct?( )A.char str[10]; str="string";B.char str[ ]="string";C.char *p="string";D.char *p; p="string";请说明原因谢谢12.Which is the output result of the following program code(
9.Which expression in following statements is not correct?( )
A.char str[10]; str="string";
B.char str[ ]="string";
C.char *p="string";
D.char *p; p="string";
请说明原因谢谢
12.Which is the output result of the following program code( )
char s[ ]="student";
printf(“%s%d”,s+3,sizeof(s));
A.student7 B. dent7 C.dent8 D.student8
这题答案是什么呢
9.Which expression in following statements is not correct?( )A.char str[10]; str="string";B.char str[ ]="string";C.char *p="string";D.char *p; p="string";请说明原因谢谢12.Which is the output result of the following program code(
9.char str[10];这个定义系统分配了一个连续的存储空间给数组,str是一个数组名,是数组的首地址,数组的首地址分配了就不会改变了,所以str就是一个常量指针了,就不能再继续赋值了.至于B答案,那是因为没有给数组分配存储空间,而只是一个声明,就相当于一个指针.
答案是C.
s是字符串的首地址指向的是s,而是s+3指向的是d,所以输出的是dent,遇到了字符串结束字符就结束了.
sizeof()求的是字符串所占的字节数,字符串"student"其实是"student\0"共8个字符.