设有如下函数定义,则输出结果为_______。 char*fun(char*str) { char*p=str; while(*p) {if(*p>'d')continue; p++; } return p; } main() { printf("%s\n",fun("welcome!")); }
A.welcome
B.come!
C.w
D.程序进入死循环
第1题:
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。
例如:str1=“How do”,str2=“you do?”,结果输出: How do you do?
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 40
void fun(char*str1,char *str2)
{
int i=0;
char *pl=str1;
char*p2=str2;
while(【 】)
i++;
for(;【 】;i++)
*(p1+i)=【 】;
*(p1+i)='\0';
}
main()
{
char str1[N],str2[N);
clrscr();
printf("*****Input the string str1 & Str2*****\n");
printf("\nstr1:");
gets(str1);
printf("\nstr2:");
gets(str2);
printf("**The string str1 & str2**\n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*****The new string *****\n");
puts(str1);
}
第2题:
以下程序运行后的输出结果是( )。
include
char*ss(char*s)
{char*p,t;
P=s+1;t=*s;
while(*p){ *(P-1)=*P;P++;}
*(P-1)=t;
return s;
}
main()
{char*p,str[10]="abcdefgh";
p=ss(str);
printf("%s\n",p);
}
第3题:
以下程序运行后,如果从键盘上输入ABCDEF<回车>,则输出结果为______。 #include<stdio.h> #include<string.h> func(char str[]) { int num=0; while(*(str+num)!='\0') num++; return(num);p } main() { char str[10],*p=str; gets(p);printf("%d\n",func(P)); }
A.8
B.7
C.6
D.5
第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题:
设有如下函数定义,则输出结果为______。 char*fun (char*str) {char*p=str; while(*p) { if(*p>'d') continue; p++; } return p; } main() { printf("%s\n",fun("welcome!")); }
A.welcome!
B.come!
C.w
D.程序陷入死循环中
第6题:
设有如下函数定义。若在主函数中用语句cout<<f("good")调用上述函数,则输出结果为(48)。 int f(char *s){ char *p=s; while(*p! ='\0')p++; return(p-s); }
A.3
B.4
C.5
D.6
第7题:
char str[ ]= "Hello";
char *p=str;
int n=10;
sizeof(str)=( )
sizeof(p)=( )
sizeof(n)=( )
void func(char str[100])
{ }
sizeof(str)=( )
第8题:
char*getmemory(void)
{ char p[]=”hello world”;
return p;
}
void test(void)
{
char *str=null;
str=Getmemory();
printf(str);
} 请问运行 Test 函数会有什么样的结果.
第9题:
char *GetMemory(void){ char p[] = "hello world";return
p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes
t 函数会有什么样的结果?
第10题:
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2倒置后接在字符串str1后面。
例如:str1=“How do”,str2=“?od uoy”,结果输出:“How do you do?”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 40
void fun(char *str1,char *str2)
{
int i=0,j=0,k=0,n;
char ch;
char *p1=str1;
char *p2=str2;
while(*(p1+i))
i++;
while(*(p2+j))
j++;
n=【 】;
for(;k=j/2;k++,j--)
{
ch=*(p2+k);
*(p2+k)=*(p2+j);
*(p2+j)=ch;
}
【 】;
for(;【 】;i++)
*(p1+i)=*p2++;
*(p1+i)='\0';
}
main()
{
char str1[N],str2[N];
int m,n,k;
clrscr();
printf("***Input the string str1 & str2
***\n");
printf("\nstr1:");
gets(str1);
printf("\nstr2:");
gets(str2);
printf("***The string str1 & str2 ***\n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*** The new string ***\n");
puts (str1);
}
第11题:
下面的程序各自独立,请问执行下面的四个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);
}
}
第12题:
串的操作函数str定义为: int str(char*s){ char*p=s; while(*p!=’\0')p++; return p=s; } 则str("abcde")的返回值是 ( )
A.3
B.4
C.5
D.6
第13题:
请补充函数fun,该函数的功能是比较字符串str1和str2的大小,井返回比较的结果。
例如: 当str1=“cdef",str2=“cde”时,函数fun()返回“>”。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include< stdio, h>
include<conio. h>
define N 80
char *fun (char *str1,char *str2)
{
char *p1=str1, *p2=str2;
while (*p1 & & *p2 )
{
if (【 】)
return "<";
if(【 】)
return ">";
p1++;
p2++;
}
if (*p1=*p2)
return "==";
if (*p1==【 】)
return "<";
else
return ">";
}
main()
{
char str1 [N], str2 [N];
clrscr ();
printf ("Input str1: \n");
gets (str1);
printf ("Input str2: \n");
gets (str2);
printf ("\n*****the result*****\n");
printf ("\nstr1 %s str2", fun (str1, str2) );
}
第14题:
请补充函数fun(),该函数的功能是判断一个数是否为回文数。当字符串是回文时,函数返回字符申:yes!,否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如:abcba。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<string.h>
include<stdio.h>
char *fun(char*str)
{
char *p1,*p2;
int i, t=0;
p1=str;p2=str+strlen(str)-1;
for (i=0;【 】;i++)
if(【 】)
{
t=1;
break;
}
if (【 】)
return("yes!");
else
return("no!");
}
main()
{
char str[50];
printf("Input;");
scanf("%s",str);
printf("%s\n",fun(str));
}
第15题:
以下程序的输出结果是【 】。
include <stdio.h>
include <string.h>
char *fun(char *0
{ char *p--t;
return (p+strlen(t)/2);
}
main()
{ char *str="abcdefgh";
str=ftm(str);
puts(str);
}
第16题:
以下函数fun的功能是返回str所指字符串中以形参c中字符开头的后续字符串的首地址,例如,str所指字符串为Hello!,c中的字符为e,则函数返回字符串ello!的首地址。若str所指字符串为空或不包含c中的字符,则函数返回NULL,请填空。char *fun(char *str,char c){ int n=0; char *p=str; if(p!=NULL) while(p[n]!=c&&p[n]!=’\0’) n++; if(p[n]==’\0’) return NULL; return();}
第17题:
请读程序: # includde<stdio.h> # include<string.> void fun(char * s) {char a[10]; strcpy(a,"STRING"); s=a; } main() { char*p; fun(p); print{("%s\n",p); } 上面程序的输出结果(表示空格) ( )
A.STRING
B.STRING
C.STRING
D.不确定的值
第18题:
void setmemory(char **p, int num)
{ *p=(char *) malloc(num);}
void test(void)
{ char *str=NULL;
getmemory(&str,100);
strcpy(str,"hello");
printf(str);
}
运行test函数有什么结果?( )
第19题:
有关内存的思考题
1. void getmemory(char *p)
{ p=(char*)mallol(100);
}
void test(void)
{
char * str =null;
getmemory(str);
strcpy(str,”hello,world”);
printf(str);
}
请问运行 Test 函数会有什么样的结果
第20题:
void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str
= NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数
会有什么样的结果?
第21题:
Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}void
Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello"); printf(str); }请问
运行Test 函数会有什么样的结果?
第22题:
请补充函数fun(),该函数的功能是:把一个字符串中的字符(字母)按从小到大排序,并把这个全部由字母组成的字符串保存在原串中,函数返回这个字符串的长度。例如;输入“cixbr2.3”,如果为bcirx,字符串长度为5。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
include <stdio.h>
define N 20
int fun (char *str)
{
int i=0,j=0,k=-0,m=0;
char t;
char *p=str;
while(*p)
{
if((*p>='A'&&*p<='Z')||(*p>='a'
&&*p<='z'))
【 】
p++;
}
*(str+i)='\0';
【 】;
while(*(p+j))
{
k=j;
【 】;
while (*(p+k))
{
if(*(p+k)<*(str+m)
{
t=*(str+m);
*(str+m)=*(p+k);
*(p+k)=t;
}
k++;
}
j++;
}
return i; }
main()
{
char str[81];
iht n;
clrscr();
printf("Input the original string ");
gets(str);
printf("*** The Original string ***In");
puts(str);
printf("*** The nwe string ***\n");
n=fun(str);
puts(str);
printf("***The length of new string is:
%d***\n",n);
}
第23题:
以下程序的输出结果是【 】。
include <stdio.h>
include <string.h>
char *fun(char *t)
{ char *p=t;
return (p+strlen(t)/2);
}
main()
{ char *str="abcdefgh";
str=ftm(str);
puts(str);
}