niusouti.com

以下程序输出的结果是()。includeusing namespace std;int main(){int **x,*y,z=10;y=以下程序输出的结果是( )。 #include<iostream> using namespace std; int main() { int **x,*y,z=10; y=&z; x=&y; cout<< **x+1<<endl; return 0; }A.11B.x的地址C.y的地址D.运行错误

题目
以下程序输出的结果是()。includeusing namespace std;int main(){int **x,*y,z=10;y=

以下程序输出的结果是( )。 #include<iostream> using namespace std; int main() { int **x,*y,z=10; y=&z; x=&y; cout<< **x+1<<endl; return 0; }

A.11

B.x的地址

C.y的地址

D.运行错误


相似考题
参考答案和解析
正确答案:A
解析:执行语句y=&z;后,指针y指向了变量z。执行语句x=&y;后,指针**x指向z。所以**x的值为z的值10,那么程序最后输出为11。
更多“以下程序输出的结果是()。#include<iostream>using namespace std;int main(){int **x,*y,z=10;y= ”相关问题
  • 第1题:

    以下程序执行后的输出结果是( )。include usingnamespacestd;void try(int,int,int,in

    以下程序执行后的输出结果是( )。 #include <iostream> using namespace std; void try(int,int,int,int); int main ( ) { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = X*X; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。下面是正确解答。根据程序逐步分析:①程序中定义了一个名为try的void型函数,即函数try()没有任何返回值。②而try()函数在主函数中是以一条独立语句的方式被调用的,且主函数最后输出变量r的值。③但在主函数中,并没有对变量r赋值。④在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以,虽然在函数try()中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第2题:

    有如下程序: include using namespace std; void f1(int& x, int& y){int z=

    有如下程序:

    #include<iostream>

    using namespace std;

    void f1(int& x, int& y){int z=x; x=y; y=z;)

    void f2(int x, int y){int z=x; x=y; y=z;}

    intmain(){

    int x=10, y=26;

    f1(x, y);

    f2(x, y);

    cout<<y<<end1;

    return 0;

    }

    运行时的输出结果是( )。

    A) 10

    B) 16

    C) 26

    D) 36

    A.

    B.

    C.

    D.


    正确答案:A

  • 第3题:

    下面程序输出的结果是( )。 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
    解析:函数的参数是引用,故能实现引用调用。

  • 第4题:

    有以下程序: include using namespace std; voidt(intx,inty, intcp,intdp) {cp=x*x+y

    有以下程序:

    include <iostream>

    using namespace std;

    void t(int x,int y, int cp,int dp)

    {

    cp=x*x+y+y;

    dp=x*x-y*y;

    }

    int main()

    {

    int a=4,b=3,c=5,d=6;

    t(a,b,c,D) ;

    cout<<c<<","<<d<<end1;

    return 0;


    正确答案:56
    5,6 解析:在主函数中定义了a、b、c、d等4个整型变量,并给他们赋初值4、 3、5、6。然后调用函数t(),把a、b、c和d的值依次传递给相应的形参x、y、cp、卸,形参和实参之间不再存在联系。进入函数t()后,执行其中的语句序列。函数t()调用返回后,输出的c和d的值依旧是5和6。

  • 第5题:

    下面程序执行的结果是【 】 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。

  • 第6题:

    请填写空格: include using namespace std; void fun(int x,int y,int * z) { *2 = x

    请填写空格:

    include<iostream>

    using namespace std;

    void fun(int x,int y,int * z)

    { *2 = x + y;}

    void main()

    {

    int a=100,b=100,c,*p=&c;

    fun(a,b,p);

    【 】; //输出调用fun函数后返回a、b的和。

    }


    正确答案:cout*p;
    cout*p; 解析:函数 fun()通过指针可以带回返回值,a、b的和存放在*p中。

  • 第7题:

    以下程序执行后输出的结果是【】。 include using namespace std; int fac(int a,int b){

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

    include<iostream>

    using namespace std;

    int fac(int a,int b){

    return(b-a)*a;

    }

    int main(){

    int x=3,y=4,z=5,result;

    result=fac(fac(x,y),fac(x,z));

    cout<<result<<endl;

    return 0;

    }


    正确答案:9
    9 解析:在main()函数中执行result=fac(fac(x,y),fac(x,2));调用了三次fac()函数: fac(x,y)的值为3,fac(x,z)的值为6,fac(3,6)得到的值为9。

  • 第8题:

    如下程序执行后的输出结果是【】。include using namespace std; class Base { public:

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

    include <iostream>

    using namespace std;

    class Base

    {

    public:

    Base(int x,int y)

    {

    a=x;

    b=y;

    }

    void Show()

    {

    cout<<"Base: "<<a<< ',' <<b<<" ";

    }

    private:

    int a,b;

    };

    class Derived : public Base

    {

    public:

    Derived(int x, int y, int z) : Base(x,y),c(z) { }

    void Show()

    {

    cout<<"Derived:"<<c<<end1;

    }

    private:

    int c;

    };

    int main()

    {

    Base b(100,100),*pb;

    Derived d(10,20,30);

    pb=&b;

    pb->Show();

    pb=&d;

    pb->Show();

    return 0;

    }


    正确答案:Base:100100 Base:1020
    Base:100,100 Base:10,20 解析:本题考核对象指针的应用。主函数中通过对象指针pb.分别调用其类成员函数Show()和派生类成员函数Show()先后输出 Base:100,100Base:10,20。

  • 第9题:

    以下程序执行后的输出结果是include using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #include <iostream> using namespace std; void try(int,int,int,int); int main () { int x,y,z,r; x =1 ; y = 2; try(x,y,z,r); cout<<r<<endl; return 0; } void try(int x,int y,int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在c++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第10题:

    下面程序输出的结果是( )。 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
    解析:对象创建的次序为:先基类,后派生类;析构时,先派生类,后基类。

  • 第11题:

    请选出以下程序段的输出结果 ( )。include using namespace std;define MIN(x,y)(x)<

    请选出以下程序段的输出结果 ( )。 #include <iostream> using namespace std; #define MIN(x,y) (x)<(y) ?(x) : (y) int main () { int i,j,k; i=10; j=15; k=10*MIN(i,j); cout<<k<<end1; return 0; }

    A.15

    B.100

    C.10

    D.150


    正确答案:A
    解析:本题考查对宏定义的掌握程度。本题最常见的错误就是想当然地先把i、j代入MIN(i,j),得到值10,然后在计算表达式k=10*10=100,得到答案100。其实不然,在使用宏替换时,应该充分理解宏替换仅是简单地用所说明的字符串来替代对应的标识符。所以,应当先把宏定义代入到表达式k=10*MIN(i,j)中,得到:k=10*1015?10:15,再按照运算符的优先级和结合性计算,最后得到k=15。

  • 第12题:

    有如下程序: include using namespace std; int fun1(int x) {return++x;} int fun2(i

    有如下程序:

    include<iostream>

    using namespace std;

    int fun1(int x) {return++x;}

    int fun2(int &x) {return++x;}

    int main(){

    int x=1,y=2;

    y=fun 1(fun2(x));

    cout<<X<<','<<y;

    return 0:

    }

    程序的输出结果是______。


    正确答案:23
    2,3 解析:此题考查的是函数传值。int fun1(int x) {retum++x;}函数中参数为传值,所以对于函数的操作不会改变实参的值,而函数int fun2(int &x){retum++x;}中的参数为引用,对于形参的操作会改变实参的值。在主函数中调用fun2(x)后,变量x的值修改为2,所以在调用fun1函数时其形参值为2,即运算后y的值被赋值为3,所以输出为2,3。

  • 第13题:

    有以下程序: include using namespace std; char *x[]={"First", "Second", "Third"

    有以下程序: #include <iostream> using namespace std; char *x[]={"First", "Second", "Third" }; void f(char *z[ ]) { cout<<*z++<<end1; } int main ( ) { char **y; y=x; f(y); return 0; }

    A.产生语法错误

    B.First

    C.Secpnd

    D.Third


    正确答案:B
    解析:程序首先定义全局指针数组x,并赋初值。在函数f()中,语句“cout*z++end1;”是输出*z指向的字符串,然后指向下一个指针。由于在主函数中,指针y已初始化指向指针数组x,所以执行f(y)后,程序输出指针数组x中的第一个字符串"First"。

  • 第14题:

    若有以下程序:include using namespace std;void sub(int x,int y, int *z){ *z = y+

    若有以下程序: #include <iostream> using namespace std; void sub(int x,int y, int *z) { *z = y+x; } int main() { int a,b, c; sub (8,4,&a) ; sub (6, a, &b) ; sub(a,b,&c) ; cout<<a<<", "<<b<<", "<<c<<end1; return 0; } 程序运行后的输出结果是( )。

    A.12,18,30

    B.-12,6,8

    C.6,8,10

    D.12,-18,16


    正确答案:A
    解析:本题考核对指针作为函数的参数的理解程度。分析程序:①函数sub()为void型。函数的形参中,z是一个血型的指针变量,因此它只能从实参接收一个血型变量的地址。②在函数sub()体中,语句:“*z=y+x;”的功能是把形参y与x的和值放入形参z所指的存储单元中。③在主函数中,3次调用sub()函数。第一次调用时,把8和4分别传递给形参x和y,把主函数中变量a的地址传递给形参z,这样形参就指向了主函数中的变量a,在sub函数中执行语句“*z=y+x;”后,把12放入z所指的存储单元中,即变量a被赋值12。以此类推,最后b被赋值18,c被赋值30。所以最后输出是12,18,30。

  • 第15题:

    以下程序输出结果是():includeusing namespace std;void add(int X,int y,int *z){*z

    以下程序输出结果是( ): #include<iostream> using namespace std; void add(int X,int y,int *z) { *z=y+x; } int main() { int a,b,c; add(8,4,&a); add(6,a,&b); add(a,b,&c); cout<<a<<","<<b<<","<<c<<end1; return 0;

    A.12,10,14

    B.12,18,30

    C.12,6,18

    D.12,14,30


    正确答案:B

  • 第16题:

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

  • 第17题:

    下列程序运行时的输出结果是______。 include using namespace std; void Xfun(int&

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

    include<iostream>

    using namespace std;

    void Xfun(int&, int&);

    int main(){

    int a=3, b=4;

    Xfun(a, B) ;

    cout<<a*a+b<<end1;

    return 0;

    }

    void Xfun(int& x, int& y){

    int z=x;

    x=y; y=z;

    }


    正确答案:19
    19

  • 第18题:

    若有以下程序:include using namespace std;class A{private: int x;protected: int

    若有以下程序: #include <iostream> using namespace std; class A { private: int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx () { return x; }; class B : protected A { public: void setvalue(int a, int b, int c) { setx (a); y=b; z=c; } void display() { cout<<getx ( ) <<", "<<y<<", "<<z<<", "<<end1; } }; int main () { B obj; obj.setvalue(5, 6, 7); obj.display ( ); return 0; } 程序运行后的输出结果是( )。

    A.产生语法错误

    B.7,6,5

    C.5,6,7

    D.7,5,6


    正确答案:C
    解析:本题考核保护继承中对类成员的访问权限。①在保护继承中,基类公有成员和保护成员都以保护成员身份出现在派生类中,而基类私有成员不可访问。②基类的公有成员和保护成员被继承以后作为派生类的保护成员,这样,派生类的其他成员可以直接访问它们。③由保护派.生的类声明的对象,不能访问任何基类的成员。在本题中,基类A中的数据成员y和函数setx,经过保护继承以后,在派生类B中成为保护成员,派生类B的对象不能访问它们。而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

  • 第19题:

    下面程序的运行结果是【】。 include using namespace std; void fun(int&a,int b=3)

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

    include <iostream>

    using namespace std;

    void fun(int &a, int b=3)

    {

    static int i=2;

    a = a + b + i;

    i = i + a;

    }

    int main()

    {

    int x=5, y=2;

    fun(x, y);

    cout<<x<<",";

    fun(x);

    cout<<x<<end1;

    return 0;

    }


    正确答案:923
    9,23 解析:本题主要考察C++中变量的作用域、存储类别和参数默认值的使用。本题主函数中,第1次调用fun()函数时,利用实参x和y将5和2分别赋值给形参a和b;由于形参a为传址方式传值,因此在函数fun()内部,由于a的改变:a =a+b+i=5+2+2=9。导致实参x值也变为9,因此程序第1次输出x值为9。
    此后静态局部变量i值变为:i=i+a=2+9=11。
    主函数第2次调用fun()时,只给出了一个实参x,其值由上述计算应该为9,而另一个参数由于fun()函数定义中为形参b指定了默认值3,因此此时程序将把3作为形参b的值代入fun()函数中去。类似上面计算有:a=a+b+i=9+3+11=23。
    由于形参a采用传址方式传值,因此实参x值也随之变为23,则程序第2次输出值应该为23。故程序整体输出为“9,23”。

  • 第20题:

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

  • 第21题:

    以下程序执行后的输出结果是includeusing namcspace std;void try(int,int,int,int);

    以下程序执行后的输出结果是 #include<iostream> using namcspace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第22题:

    以下程序执行后的输出结果是()。includeusing namespace std;void try(int,int,int,in

    以下程序执行后的输出结果是( )。 #include<iostream> using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<endl; return 0; } void try(int x,int y, int z,int r) { z = x+y; X = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D

  • 第23题:

    以下程序执行后的输出结果是include.using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #include<iostream>. using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。