第1题
class Bag {
public:
Bag(int p,char s='M'):price(p),size(s) { count++; }
~Bag() { count--; }
int GetPrice() { return price; }
int GetPrice() const { return price; }
void SetPrice(int val) const { price=val; }
private:
int price;
char size;
static int count;
};
下列关于类成员的叙述中,正确的是( )。
A. 成员函数GetPrice存在重定义
B.构造函数的参数不能设置默认值
C.析构函数中不能访问静态数据成员
D.成员函数SetPrice不能定义为常函数
第2题
有以下程序
#include<stdio.h>
#include<string.h>
void fun(char *w,int m)
{ char s,*p1,*p2;
p1=w;p2=w+m-1;
while(p1<p2){s=*p1;*p1=*p2;*p2=s;p1++;p2--;}
}
main()
{ char a[]="123456";
fun(a,strlen(a));puts(a);
}
程序运行后的输出结果是A.654321
B.116611
C.161616
D.123456
【我提交的答案】: C |
【参考答案与解析】: 正确答案:A |
解析:strlen函数的作用是计算字符串的长度,不包括'\0'在内。所以形参m的值为6,根据fun函数中pl和p2的赋值一个指向第一个字符'1',一个指向最后一个字符'6'。然后比较大小,且根据条件互换,直到条件为假跳出循环。第一次循环后为623451,第二次653421,第三次654321。即fun函数实现将一个字符串逆序存放。所以答案为A)。
第3题
#include<stdio.h>
#include<string.h>
void fun(char *w,int m)
{ char s,*p1,*p2;
p1=w;p2=w+m-1;
while(p1<p2){s=*p1;*p1=*p2;*p2=s;p1++;p2--;}
}
main()
{ char a[]="123456";
fun(a,strlen(a));puts(a);
}
程序运行后的输出结果是
A.654321
B.116611
C.161616
D.123456
第4题
A. -1
B.0
C."abcdef"
D."abdef"
第5题
A.-1
B.0
C.abcdef
D.abdef
第7题
若输入“abcdef”“abdef”,下述程序的输出结果为( )。
#include<stdio.h>
#include<string.h>
main
{ int n;
char s1[20],s2[20],*p1,*p2;
scanf("%s",s1);
scanf("%S",s2);
p1=s1;
p2=s2;
n=strcmp(p1,p2);
printf("Vood\n",n);
}
A. -1
B.0
C."abcdef"
D."abdef"
【我提交的答案】: A |
【参考答案与解析】: 正确答案:D |
本题考查字符串比较函数strcmp(s1,s2),若s1>s2,则返回1;若s1=s2,则返回0;若s1<s2,则返回-1。字符串依次比较的是它们字符的ASCIl码值。
不明白为什么输出的是字符串
第8题
#include<stdio.h>
#include<ctype.h>
void fun(char *P)
{int i=0;
while(p[i])
{if(p[i]==‘ ’&&islower(p[i-1]))p[i-1]=p[i-1]=‘a’+‘A’;
i++;
}
}
main( )
{char s1[100]=”ab cd EFG!”;
fun(a1);printf(”%s\n”,s1);
}
程序运行后的输出结果是( )。
A.ab cd EFG!
B.Ab Cd EFg!
C.aB cD EFG!
D.ab cd EFg!
第9题
A.654321
B.116611
C.161616
D.l23456
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!