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

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


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

    执行如下程序后的输出结果是【】。include include using namespace std;int ma

    执行如下程序后的输出结果是【 】。

    include <iostream>

    include <fstream>

    using namespace std;

    int main ( )

    {

    char s[25];

    ofstream fl("data.txt");

    f1<<"C++ Programming";

    f1.close ();

    ifstream f2 ("data.txt");


    正确答案:C++
    C++ 解析:程序先在当前目录下建立一个data文本文件,并写入“C++ Programming”。然后打开该文件,将其中的数据输入到变量s中,由于采用提取符“>>”读时遇到空格终止,所以最后字符数组s中存放的是“C++”。

  • 第2题:

    程序的输出结果是【 】。 include using namespace std; class A{ int x; public: A(int

    程序的输出结果是【 】。

    include <iostream>

    using namespace std;

    class A{

    int x;

    public:

    A(int x=1):x(x){cout<<x;}

    };

    void main(){

    A a,b(2),c(3);

    }


    正确答案:123
    123 解析:a对象使用和默认的构造函数,b对象使用2来初始化对象c对象使用3来初始化对象,输出相应的值后,结果变为123。

  • 第3题:

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

    下列程序的输出结果是【 】。

    include <iostream>

    using namespace std;

    int main()

    {

    int data=1;

    int &r = data;

    data+=5;

    r+=5;

    cout<<data<<end 1;

    return 0;

    }


    正确答案:11
    11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后data的值为11。

  • 第4题:

    下列程序的输出结果是______。 include using namespace std; void fun(int &rf) {

    下列程序的输出结果是______。

    include<iostream>

    using namespace std;

    void fun(int &rf)

    {

    rf*=2;

    }

    int main()

    {

    int num=500;

    fun(num);

    cout<<num<<endl;

    return 0;

    }


    正确答案:1000
    1000 解析:本题考核引用作为函数参数的使用。引用作为形参时,它实际上就是实参,函数对形参的访问和修改就是对实参的访问和修改,题中函数fun对形参的操作是自增2倍,所以经过函数调用后,实参的值自增2倍,即输出1000。

  • 第5题:

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

    下列程序的输出结果是______。

    include<iostream>

    using namespace std;

    int main()

    {

    int data=l;

    int &r = data;

    data+=5;

    r+=5;

    cout<<data<<endl;

    return 0;

    }


    正确答案:11
    11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后 data的值为11。

  • 第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题:

    若有如下程序段: 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和一个长整型指针变量q。首先通过语句“a=(long*)p;”,把p的地址值强制转换为长整型地址值并赋值给小然后执行“q++”,地址值增加了4,执行语句“r=(char*)q;”,把长整型指针变量q的值再强制转换成字符型地址值并赋给r,r的值应为字符串中字符“e”的地址。最后输出r指向的字符串。

  • 第8题:

    若有以下程序: include using namespace std; int main() {char str[10];cin>>str;co

    若有以下程序:

    include <iostream>

    using namespace std;

    int main()

    {

    char str[10];

    cin>>str;

    cout<< str<<end1;

    return 0;

    }

    当输入为:

    This is a program!

    那么执行程序后的输出结果是【 】。


    正确答案:This
    This 解析:本题考核C++的标准输入/输出。提取符可以从输入流中读取一个字符序列,即一个字符串。在处理这种字符序列时,字符串被认为是一个以空白字符结束的字符序列。因此,本题得到的输入仅仅是第一个空白符之前的字符序列 This。所以程序最后的输出是This。

  • 第9题:

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

  • 第10题:

    有以下程序: include include using namespace std; int main() {char arr[

    有以下程序: #include<iostream> #include<string> using namespace std; int main() { char arr[2][4]; strcpy(arr[0],"you"); strcpy(arr[1],"me"); arr[0][3]='&'; cout<<arr[0]<<end1; return 0; } 执行后的输出结果是( )。

    A.you&me

    B.you

    C.me

    D.err


    正确答案:A
    解析:本题考核字符串函数的使用。主函数中,首先定义了千个二维字符数组art。语句“strcpy(arr,"you");”中的alt代表二维字符数组的首元素地址,此语句的作用是将字符串“you”复制到arr数组的前4个元素中,第4个元素的值为'\0'。语句“strcpy(arr[1],"me");”的作用是把字符串“me”赋值到arr数组的第2行。语句“arr[0][3]='及';”的作用是用字符'&'取代了原来arr[0][3]中的字符'\0'。所以程序最后输出you&me。

  • 第11题:

    有下列程序段: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。

  • 第12题:

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

  • 第13题:

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

  • 第14题:

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

  • 第15题:

    以下程序的输出结果是【】。 include using namespace std; int main(){ int sum,i; for(

    以下程序的输出结果是【 】。

    include<iostream>

    using namespace std;

    int main(){

    int sum,i;

    for(sum=0,i=1;i<5;i++)sum+=i;

    cout<<sum<<endl;

    return 0;

    }


    正确答案:10
    10 解析:本题程序实现的是计算1+2+3+4的和,因此最后输出为10。

  • 第16题:

    下面程序运行输出的结果是【】。 include using namespace std; int main(){char a[]="C

    下面程序运行输出的结果是【 】。

    include <iostream>

    using namespace std;

    int main(){

    char a[]="Chinese";

    a[3]='\0';

    cout<<a<<endl;

    return 0;

    }


    正确答案:Chi
    Chi 解析:字符串的结束标识是'\0',输出字符串时,到第一个'\0'输出结束,而不管其后是否还有数据,因此本题输出为字符中的前3个字符。

  • 第17题:

    下列程序的输出结果为( )。 #include (iostream) using namespace std; void main( ) char,a[ ] = { "hello" ," the" ," world" }; char * * pa = a: pa + +; cout << * pa << ENDL; }

    A.hello

    B.the

    C.world

    D.hellotheworld


    正确答案:B
    解析:指针与数组对应关系,*p++访问数组第二个元素。

  • 第18题:

    下列程序的输出结果是【】include using namespace std; int main() { int num=500; int

    下列程序的输出结果是【 】

    include<iostream>

    using namespace std;

    int main()

    {

    int num=500;

    int &ref=num;

    ref +=100;

    cout<<num<<end1;

    return 0;

    }


    正确答案:600
    600 解析:考核引用的使用。题中整型变量ref定义为num的引用,所以对ref的作用等同于对num的作用,所以ref加上100后, num的值也就变成了600。

  • 第19题:

    有以下程序,其输出结果是()。include using namespace std;int main(){ char a[10]={'

    有以下程序,其输出结果是( )。 #include <iostream> using namespace std; int main(){ char a[10]={'1','2','3','4','5','6','7','8','9',0},*p; int i=8; p=a+i; cout<<p-3<<endl; return 0; }

    A.6789

    B.6

    C.789

    D.'6'


    正确答案:A
    解析:没有下标的数组名是一个指向该数组首元素的指针,本程序实现的功能是将字符“6”及其以后的字符按字符串形式输出。

  • 第20题:

    下列程序的输出结果是______。includeinclude using namespace std;void

    下列程序的输出结果是______。

    include <iostream.h>

    include <cstring.h>

    using namespace std;

    void fun(const char*s,char &C) {c=s[strlen (s)/2];}

    int main {)

    {

    char str [] ="ABCDE";

    char ch=str[1];

    fun(str,sh);

    cout<<Ch;

    return 0;

    }


    正确答案:C
    C 解析:本题考核数组的定义、使用以及函数的调用。fun函数的作用是将字符串str中间的字符赋值给地址传入的变量ch。所以ch的值将被修改为‘C’。

  • 第21题:

    下列程序的输出结果是【】 include using namespace std; int &get Var(int*pint) {

    下列程序的输出结果是【 】

    include<iostream>

    using namespace std;

    int &get Var(int*pint)

    {

    return *pint;

    }

    int main()

    {

    int a=10;

    getvar(&A) =20;

    cout<<a<<end1;

    return 0;

    }


    正确答案:20
    20 解析:本题考核引用的使用。题中函数getVar返回的为实参的引用,即将a的引用赋值为20,所以最后输出a的值为20。

  • 第22题:

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

  • 第23题:

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

    下面的程序输出的结果是( )。 #include <iostream> using namespace std; void main(){ int a=2; int &c=a; a++; cout<<c; }

    A.2

    B.3

    C.4

    D.*a


    正确答案:B
    解析:c是a的引用,故a++相当于c++。