niusouti.com

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

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


相似考题
更多“下列程序的输出结果是 #inClUde<iostream> using namespace std; intmain() { Char a[]="HellO,W ”相关问题
  • 第1题:

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

  • 第2题:

    有下列程序段:include using namespace std;int main() { char b[]= "Hello,you"; b[

    有下列程序段: #include <iostream> using namespace std; int main() { char b[] = "Hello,you"; b[5] = 0; cout<<b<<end1; return 0; } 执行此程序后,得到的输出结果是( )。

    A.Hello,you

    B.Hello0you

    C.Hello

    D.0


    正确答案:C
    解析:本题考核字符数组的特性。本题表面上看起来很简单,其实不然,出题者在题中隐藏了一个陷阱。常见的错误答案是:字符数组b初始化后,得b[5]='',执行“b[5]=0;”后,把0代替b[5]中的','即可。最后输出整个字符串“Hello0you”。下面是正确解答:在C++语言中规定:以字符’0’作为字符串结束标志。语句“b[5]=0;”就相当于语句b[5]='\0',即在数组b的b[5]加上了字符串结束标志,故执行该语句后,数组中存放的内容变为Hello。

  • 第3题:

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

  • 第4题:

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

  • 第5题:

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