计算机二级

下列程序的输出结果是( )。 #included<iostream> usingnamespacestd; intmain() { chara[]="Hell0,Test"; char*p=a; while(*p) { if(*p>=a&&*p<=z) cout<<char(*p+A-a); elsecout<<*P; p++; } return0; }A.hello,testB.Hello,TestC.HELLO,TESTD.hELLO,tEST

题目

下列程序的输出结果是( )。 #included<iostream> usingnamespacestd; intmain() { chara[]="Hell0,Test"; char*p=a; while(*p) { if(*p>=a&&*p<=z) cout<<char(*p+A-a); elsecout<<*P; p++; } return0; }

A.hello,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST

参考答案和解析
正确答案:C
C。【解析】用一个指针变量p指向字符数组A,在while循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序的输出结果是()。includeusing namespace std;int main()于chara[]=”Hello,Te

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() 于 chara[]=”Hello,Test”; Char*p=a; while(*p) { if(*p)=’a’&&*p(=’z’) cout<<char(*p+’A’-’a’); else cout<<*p; p++; } return 0; }

A.hello,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST


正确答案:C
解析: 用一个指针变量p指向字符数组a,在while循环中,当不指向数组尾时,将小写字母转换为大写字母!然后将其输出。

第2题:

下列程序的输出结果是( )。 include using namespace std; int main() {

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]="Hello,Test"; char *p=a; while(*p) { if(*p>='a'&&*p<='z') cout<<char(*p+'A'-'a'); else cout<<*p; p++; } return 0; }

A.hello,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST


正确答案:C
解析:用一个指针变量p指向字符数组a,在while循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

第3题:

下列程序的输出结果是 inClUde using namespace std; intmain() { Char a[]="HellO,W

下列程序的输出结果是

#inClUde<iostream>

using namespace std;

intmain()

{

Char a[]="HellO,World";

Char*ptr=a;

while(*ptr)

{

if(*ptr>='a'&& *ptr <='Z')

cout<<char(*ptr+'A' -'a');

else cout<<*ptr;

ptr++;

}

retur0;

}

A.HELLO,WORLD

B.Hello,world

C.hELLO,wORLD

D.hellO,world


正确答案:A
解析:本题考核while语句和if语句,while语句中if语句的作用是将小写字母变成大写字母输出,所以main函数的字符串通过while语句全部输出为大写字母。

第4题:

下列程序的输出结果是()。includeusing namespace std;int main(){char a[]=""Hello,W

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]=""Hello,World"; char*ptr = a; while(*ptr) { if(*ptr>= 'a' &&*ptr<='z') cout<<char(*ptr+'A'-'a'); else cout<<*ptr; ptr++; } retur 0; }

A.HELLO, WORLD

B.Hello, World

C.HELLO, world

D.hello, world


正确答案:A

第5题:

下列程序的输出结果是()。includeusing namespace std;int main(){char a[]="Hello,Te

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]="Hello,Test"; char*p=a; while(*p) { if(*p>='a'&&*p<='z') cout<<char(*p+'A'-'a'); else cout<<*p; p++; } re

A.hllo,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST


正确答案:C
解析: 用一个指针变量p指向字符数组a,在while循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

第6题:

下列程序的输出结果是______。includeusing namespace std;int main() {char a []="He

下列程序的输出结果是______。 #include<iostream> using namespace std; int main() { char a []="Hello, World"; char *ptr=a; while (* ptr) { if(*ptr)= 'a'&& *ptr' <= 'z') cout << char(*ptr+'A'-'a'); else cout << *ptr; ptr++; } return 0; }

A.HELLO,WORLD

B.Hello,World

C.hELLO, wORLD

D.hello,world


正确答案:A
解析:对于str的每个字母,如果是大写字母或者是非字母,就直接打印出来。如果是小写字母,就转化成大写字母,然后打印。‘A’-‘a’正是大小写字母的ASCII码之差。

第7题:

下列程序的输出结果是()。includeusing namespace std;int main(){char a[]="Hello,Te

下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() { char a[]="Hello,Test"; char *p=a; while(*p) { if(*p>='a'&&*p<='’z') cout<<char(*p+'A'-'a'); else cout<<*p; p++; } return 0; }

A.hello,test

B.Hello,Test

C.HELLO,TEST

D.hELLO,tEST


正确答案:C
解析:用一个指针变量p指向字符数组a,在while循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

第8题:

若有以下程序段: include using namespace std; int main() {char*p="abcdefgh",*r;l

若有以下程序段:

include <iostream>

using namespace std;

int main()

{

char*p="abcdefgh",*r;

long*q;

q=(long*)p;q++;

r=(char*)q;

cout<<r<<end1;

return 0;

}

该程序的输出结果是【 】。


正确答案:efgh
efgh 解析:本题定义了一个字符型指针变量p,并通过赋初值让它指向了一个字符串,还定义了另一个字符型指针变量r和一个长整型指针变量qo首先通过语句“a=(long*)p;”,把p的地址值强制转换为长整型地址值并赋值给q,然后执行“q++;”,地址值增加了4,执行语句“F(char*)q;”,把长整型指针变量q的值再强制转换成字符型地址值并赋给r,r的值应为字符串中字符“e”的地址。最后输出r指向的字符串。

第9题:

下面程序输出的结果是()。includeusing namespace std;int fuc (char *x);int main(){

下面程序输出的结果是( )。 #include<iostream> using namespace std; int fuc (char *x); int main(){ cout<<fuc("hello")<<endl; return 0; } int fuc(char *x){ char *y=x; while(*y! ='\0')y++; return(y-x); }

A.5

B.6

C.0

D.语法错误,不能输出结果


正确答案:A
解析:函数fuc()的功能是计算字符串x的长度,因此程序的输出是5。

第10题:

下列程序的输出结果是 include usingnamespacestd; int main () {chara []="Hello,W

下列程序的输出结果是 #include <iostream> using namespace std; int main () { char a [] = "Hello,World": char*ptr = a; while (*ptr) { if(*ptr>= 'a' &&*ptr <='z' cout<<char{*ptr+'A'-'a'); else cout<<*ptr; ptr++; } return 0; }

A. HELLO. WORLD

B. Hello, World

C. hELLO, wORLD

D. hello, world


正确答案:A
解析:本题考核while语句和if语句,while语句中if语句的作用是将小写字母变成大写字母输出、所以main函数的字符串通过while语句全部输出为大写字母。