计算机二级

下列程序的输出结果是()。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++; } retu

题目
下列程序的输出结果是()。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

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序的输出结果是 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语句全部输出为大写字母。

第2题:

下列程序的输出结果是()。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

第3题:

下列程序的输出结果为includevoid main(){char*a[]={"hello","the","world"};char*

下列程序的输出结果为 #include<iostream.h> void main() { char*a[]={"hello","the","world"}; char**pa=a; pa++; cout<<*pa<<end1; }

A.hello

B.the

C.world

D.hello the world


正确答案:A
解析:本题考查的是字符数组的初始化,选项B)中用3个元素初始化大小为2的数组,越界了;选项C)中应该是2行3列的数组,题中使用3行2列初始化;选项D)中数组合后应用方括号。

第4题:

下列程序的输出结果是()。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循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

第5题:

下列程序的输出结果为 include void main( ) { char * a[ ] ={"hello},"the"," wo

下列程序的输出结果为

#include<iostream.h>

void main( )

{

char * a[ ] ={"hello},"the"," world"};

char * * pa=a;

pa++;

cout < < * pa < < endl;

}

A.hello

B.the

C.world

D.hellotheworld


正确答案:B
解析:本题主要考查的是指针数组和指向指针的指针之间的关系,其中a是指针数组,pa是指向指针数组行的指针,所以pa自加1相当于指向下一行。

第6题:

下列程序的输出结果是( )。 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循环中,当不指向数组尾时,将小写字母转换为大写字母,然后将其输出。

第7题:

下列程序的输出结果是______。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码之差。

第8题:

下列程序的输出结果是()。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循环中,当不指向数组尾时,将小写字母转换为大写字母!然后将其输出。

第9题:

下列程序的输出结果是 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语句全部输出为大写字母。