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

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


相似考题
更多“下面的程序输出的结果是( )。 include using namespace std; void main(){ 下面的程序输出的结果是( )。 #include <iostream> using namespace std; void main(){ int a=2; int c=a; a++; cout<<c; }A.2B.3C.4D.*a”相关问题
  • 第1题:

    程序的输出结果是【 】。 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。

  • 第2题:

    程序的输出结果是【 】。 include using namespace std; class A{ public: A(){a=b=2;}

    程序的输出结果是【 】。

    include <iostream>

    using namespace std;

    class A{

    public:

    A(){a=b=2;}

    A(int i,int j){a=i;b=j;}

    void display(){cout<<a<<b;}

    private:

    int a,b;

    };

    void main(){

    A m,n(4,8);

    m.display();

    n.display();

    }


    正确答案:2248
    2248 解析:m对象使用和默认的构造函数,其a与b变量的值均为2;而n变量使用4和8来初始化程序的变量,a,b的值为4和8,依次输出的结果为2248。

  • 第3题:

    以下程序的输出结果是【】。 include using namespace std; void fun() {static int a=0

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

    include <iostream>

    using namespace std;

    void fun()

    {

    static int a=0;

    a+=2;

    cout<<a;

    }

    int main()

    {

    int CC;

    for(CC=1;cc<4;CC++)

    fun();

    cout<<end1;

    return 0;

    }


    正确答案:246
    246 解析:本题考核函数调用和静态变量。在主函数中通过一个for循环调用了3次fun()函数。第1次调用fun()函数时,a的初始值为0,执行语句“a+=2;”后, a的值为2,输出2;第2次调用时,a的初始值为2,执行语句“a+=2;”后,a的值为4,最后输出4:第3次调用时,a的初始值为4,执行语句“a+=2:”后,a的值为6,最后输出6。

  • 第4题:

    以下程序的输出结果是【】。 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。

  • 第5题:

    下面程序运行输出的结果是【】。 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个字符。

  • 第6题:

    下面程序的执行结果是【】。 include include using namespace std; void main(

    下面程序的执行结果是【 】。

    include<iostream>

    include<iomanip>

    using namespace std;

    void main()

    {

    cout<<setfill('x')<<setw(10);

    cout<<"Hello"<<endl;

    }


    正确答案:xxxxxHello
    xxxxxHello

  • 第7题:

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

    下面程序输出的结果是( )。 #include <iostream> using namespace std; void swap(int &a,int &b){ int temp; temp=a; a=b; b=temp; } void main(){ int x=2; int y=3; swap(x,y); cout<<x<<y; }

    A.23

    B.32

    C.ab

    D.ba


    正确答案:B
    解析:函数的参数是引用,故能实现引用调用。

  • 第8题:

    下面的程序输出结果是()。includeusing namespace std;void add(){static int x;x++;c

    下面的程序输出结果是( )。 #include<iostream> using namespace std; void add() { static int x; x++; cout<<x<<''; } int main() { for(int i=0;i<3;i++) add(); return 0; }

    A.111

    B.123

    C.222

    D.333


    正确答案:B

  • 第9题:

    下面程序的输出结果是【】。 include using namespace std; class A {int a,b; public:A

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

    include <iostream>

    using namespace std;

    class A

    {

    int a, b;

    public:

    A()

    {

    a = b = 0;

    }

    A(int aa, int bb ) : a(aA) , b(bB)

    {

    cout <<"a="<<a<<","<<"b="<<b<<",";

    }

    ~A()

    {

    cout<<"D";

    };

    int main ( )

    {

    A x, y(2, 3);

    return 0;

    }


    正确答案:a=2b=3DD
    a=2,b=3DD 解析:本题主要考核构造函数与析构函数的应用。主函数中定义 A类对象x时无输出,定义对象y时调用构造函数输出a=2,b=3。在主函数结束前,对象x,y都调用各自的析构函数输出DD。所以最后答案为a=2,b=3DD。

  • 第10题:

    下面程序执行的结果是【 】 include using namespace std; class A{ public: static in

    下面程序执行的结果是【 】

    include<iostream>

    using namespace std;

    class A{

    public:

    static int x;

    A(inty){cout<<x+y;}

    };

    int A::x=2;

    void main(){

    A a(5);

    }


    正确答案:7
    7 解析:程序的静态变量初始化为2,而构造函数招待过程中y变量为初始化为5,故程序执行的结果为7。

  • 第11题:

    有以下程序:include using namespace std;void fun(int i,int j){ cout<<(i+j)<

    有以下程序: #include <iostream> using namespace std; void fun(int i,int j) { cout<<(i+j)<<end1; } void fun(int i) { cout<<i++<<end1; } int main() { int a=1; fun(A) ; return 0; } 该程序执行后的输出结果是( )。

    A.1

    B.2

    C.3

    D.4


    正确答案:A
    解析:本题考核函数重载这个知识点。函数fun有两种实现:第1种实现中,有两个int型形参,第2个实现中,是1个int型形参。由于这两种实现方式中形参的个数不同,形成了函数的重载。在主函数中,由于传递给函数fun()的实参为1个整型变量a,所以调用函数fun()的第2中实现,输出1。

  • 第12题:

    下面程序的输出结果是()。includeusing namespace std;void main(){ int a,b; for(a=1

    下面程序的输出结果是( )。 #include<iostream> using namespace std; void main() { int a,b; for(a=1,b=l;a<=100;a++) { if(b>=10) break; if(b%3= =1) { b+=3;continue; } } cout<<a; }

    A.101

    B.6

    C.5

    D.4


    正确答案:D
    解析:该题是对for循环语句、条件语句、中断语句的综合考察。循环for语句执行了4次,当执行第4次循环的时候b=10退出循环,输出a的值为4。

  • 第13题:

    下面程序的输出结果是【】。 include using namespace std; int d=1; fun(int p){ stati

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

    include <iostream>

    using namespace std;

    int d=1;

    fun(int p){

    static int d = 5;

    d+ =p;

    cout<<d;

    return (d) ;

    }

    void main ( ) {

    int a =3;

    cout<<fun ( a + fun (d) )<<endl;

    }


    正确答案:61515
    61515 解析:先调用fun(d),d=1执行,局部静态变量d的值为6,输出6,返回值为6;再调用 fun(a+fun(d)),即fun(9)执行,静态局部变量的值为15,输出15,返回值为15;最后再执行 main方法中的输出语句,输出fun(a+fun(d))的值15。所以程序输出结果为61515。

  • 第14题:

    以下程序的输出结果为【】。 include using namespace std; void initialize(int printNo

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

    include<iostream>

    using namespace std;

    void initialize(int printNo,int state=0);

    void initialize(int printNo=l,int state);

    int main()

    {

    initialize();

    return 0;

    }

    void initialize(int printNo,int state)

    {

    cout<<printNo<<","<<state<<end1;

    }


    正确答案:10
    1,0 解析:本题考核带有默认值的函数,本题中函数initialize()进行了两次函数原型的说明,使本来不带默认值的形参带上默认值。由于主函数中调用initialize()时没有给定实参,所以函数自动调用其参数默认值,输出1和0。

  • 第15题:

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

  • 第16题:

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

  • 第17题:

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

  • 第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;void main(){int s;for(int k

    下面程序的输出结果是( )。#include <iostream>using namespace std;void main(){int s;for(int k=2;k<6;k+=2)s=1;for(int j=k; j<6;j++) s+=j;cout<<s<<end1;

    A.9

    B.1

    C.11

    D.10


    正确答案:D

  • 第20题:

    下列程序的输出结果是【】。 include include using namespace std; void fun(c

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

    include<iostream>

    include<cstring>

    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,ch);

    cout<<ch;

    return 0;

    }


    正确答案:C
    C

  • 第21题:

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

  • 第22题:

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

  • 第23题:

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

    下面程序输出的结果是( )。 #include<iostream> using namespace std; class A{ int X; public: A(int x):x(++x){} ~A(){cout<<x;} }; class B:public A{ int y; public: B(int y):A(y),y(y){} ~B(){cout<<y;}; }; void main(){ B b(3); }

    A.34

    B.43

    C.33

    D.44


    正确答案:A
    解析:对象创建的次序为:先基类,后派生类;析构时,先派生类,后基类。