更多"设有下列程序:
#include<stdio.h>
"的相关试题:
[填空题]设有下列程序:
#include<stdio.h>
#include<string.h>
main( )
{ int i;
char s[10],t[10];
gets(t);
for(i=0;i<2;i++)
{ gets(s);
if(strcmp(t,s)<0)strcpy(t,s);
}
print f("%s/n",t);
}
程序运行后,从键盘上输入(<CR>代表回车符): DEF<CR>BADEF<CR>QTHRG<CR>,则程序的输出结果是______。
[单项选择]以下程序运行后的输出结果是
#include<stdio.h>
#include<string.h>
main( )
char x[]="STRING";
x[0]=0; x[1]='/0'; x[2]='0';
printf("%d%d/n", sizeof(x),strlen(x));
A. 6 1 B) 7 0 C) 6 3 D) 7 1
[单项选择]下列程序的运行结果是( )。
#include<stdio.h>
#include<string.h>
main( )
char*s1="abDuj";
char*s2="ABdUG";
int t;
t=strcmp(s1,s2) ;
printf("%d",t);
A. 正数
B. 负数
C. 零
D. 不确定的值
[单项选择]下列程序的输出结果是( )。
#include<stdio.h>
#include<string.h>
main( )
char a[]="/n123//";
printf("%d,%d/n",strlen(a),sizeof(a));
A. 5,6
B. 5,5
C. 6,6
D. 6,5
[单项选择]下面程序的输出结果是( )。
#include<stdio.h>
#include<string.h>
main( )
char p1[]="WHO",p2[]="who",str[50]="xyz";
strcpy(str+1,strcat(p1,p2));
printf("%s",str);
A. xyzWHOwho
B. zWHOwho
C. zWHOwho
D. xWHOwho
[单项选择]下述程序的运行结果是( )。
#include<stdio.h>
#include<string.h>
main( )
char*s1="abDuj";
char*s2="ABdUG":
int t;
t=strcmp(s1,s2);
printf("%d",t);
A. 正数
B. 负数
C. 零
D. 不确定的值
[简答题]完成下面类中成员函数的定义。
#include<iostream>
#include<string>
using namespace std;
class str
private:
char*st;
public:
str(char*a)
set(a);
str&operator=(______)
delete st;
set(a.st);
return*this;
void show( )cout<<st<<endl;
~str( )delete st;
void set(char*s)//初始化st
______
strcpy(st,s);
;
void main( )
str s1("he"),s2("she");
s1.show( ),s2.show( );
s2=s1;
s1.show( ),s2.show( );
[简答题]有以下程序,其中函数f的功能是将多个字符串按字典顺序排序( )。
# include<string.h>
void f(char*p[],int n)
char*t;int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(p[i],p[j]>0)t=p[i];p[i]=p[j];p[j]=t;)
main( )
char *p[5]="abc" ,"aabdfg" ,"abbd", "dcdbe", "cd");
f(p,5);
printf("%d/n",strlen(p[1]));
程序运行后的输出结果是( )。
[填空题]以下程序运行后输入:3,abcde<回车>,则输出结果是______。
#include <string. h>
move (char *str,int n)
char cemp; int i;
temp=str[n-1];
for (i=n-1;i>0;i--) str[i]=str[i-1);
str[0]=temp;
main( )
char s[50]; int n, i, z;
scanf(“%d,%s”,&n,s);
z=strlen(s);
for (i=1; i<=n;i++)move (s,z);
printf(“%s/n”,s);
[单项选择]以下程序中函数f( )的功能是将n个字符串按由大到小的顺序进行排序。 #include<string.h> void f(char p[ ][10],int n) { char t[20]; int i,j; for(i =O;i <n-1 ;i ++ ) for(j =i + 1 ;j < n;j ++ ) if(strcmp(p [i] ,p[j] ) <0) { strcpy(t,p[i]);strcpy(p[i] ,p[j] );strcpy(p[j] ,t); } } main ( ) { char p [ ] [ 10 ] = { "abc","aabdfg","abbd","dcdbe", "cd" }; int i; f(p,5); printf("%d/n",strlen(p[O] ) ); } 程序运行后的输出结果是
A. 6
B. 4
C. 5
D. 3
[填空题]设有下列程序:
#include<stdio.h>
#include<string.h>
main( )
int i;
char s[10],t[10];
gets(t);
for(i=0;i<2;i++)
gets(s);
if(strcmp(t,s)<0)strcpy(t,s);
print f("%s/n",t);
程序运行后,从键盘上输入(<CR>代表回车符): DEF<CR>BADEF<CR>QTHRG<CR>,则程序的输出结果是______。