有下面的程序段: char str[10],ch[]="China"; str=ch; printf("%s",str); 则运行时______。
A.将输出China
B.将输出Ch
C.将输出Chi
D.编译出错
第1题:
对于下面的程序 #include<stdio.h> #include<string.h> char * scmp(char * s1,char * s2) { if(strcmp(s1,s2)<0)return(s1); else return(s2); } main() { int i;char string[20],str[3][20]; for(i=0;i<3;i++)gets(str[i]); strcpy(string,scmp(str[0],str[1])); strcpy(string,scmp(string,str[2])); printf("%s\n",string); } 若运行时依次输入abcd、abba和abc三个字符串,则输出结果为 ______。
A.abcd
B.abba
C.abc
D.abca
第2题:
以下程序: #include<stdio.h> main() {char str[10]; scanf("%s",&str); printf("%s\n",str); } 运行上面的程序,输入字符串how are you,则程序的执行结果是( )。
A.how
B.how are you
C.h
D.howareyou
第3题:
阅读下列程序,当运行程序时,输入asd af aa z67,则输出为( )。 #include <sldio.h> int fun (char *str) { int i,j=0; for(i=0;str[i]! ='\0';i++) if(str[i]! =") str[j++]=str[i]; str[j]='\0'; } main() { char str[81]; int n; printf("Input a string:"); gets(str); fun(str); printf("%s\n",str); }
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第4题:
下列程序的输出结果是______。 char*fun(char*str,int n) { int i; char*p=str; for(i=0;i<10;i++,str++) *str='a'+i; return++p; } main() { char a[10]; printf("%s\n",fun(a,10)); }
A.ABCDEFGHIJ
B.abcdefghij
C.bcdefghij
D.不确定的值
第5题:
下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?
①void GetMemory(char * p)
{
p = (char * )malloc(100);
}
void TestMemory (void)
{
char *str = NULL;
GetMemory (str);
strcpy(str, "hello world");
prinff(str);
}
② char * GetMemory (void)
{
char p[ ] = "hello world";
return p;
}
void TestMemory (void)
{
char * str = NULL;
str = GetMemory( );
printf(str);
}
③void GetMemory(char * * p, int num)
{
* p = (char * )malloc(num);
}
void TestMemory (void)
{
char * str = NULL;
GetMemory(&str, 100);
strcpy( str, "hello" );
printf(sir);
}
④void TestMemory (void)
{
char *str = (char * )malloe(100);
strepy (str, "hello" );
free ( str );
if(str ! = NULL)
{
strepy( str, "world" );
printf(str);
}
}