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/07/17 23:51:31
![9.Which expression in following statements is not correct?( )A.char str[10]; str=](/uploads/image/z/14058626-50-6.jpg?t=9.Which+expression+in+following+statements+is+not+correct%3F%EF%BC%88+%EF%BC%89A%EF%BC%8Echar+str%5B10%5D%3B+str%3D%22string%22%3BB%EF%BC%8Echar+str%5B+%5D%3D%22string%22%3BC%EF%BC%8Echar+%2Ap%3D%22string%22%3BD.char+%2Ap%3B+p%3D%22string%22%3B%E8%AF%B7%E8%AF%B4%E6%98%8E%E5%8E%9F%E5%9B%A0%E8%B0%A2%E8%B0%A212.Which+is+the+output+result+of+the+following+program+code%EF%BC%88)
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个字符.