niusouti.com

下面程序输出的结果是( )。 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.23B.32C.abD.ba

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


相似考题
更多“下面程序输出的结果是( )。 #include <iostream> using namespace std; void swap(int ”相关问题
  • 第1题:

    下面程序的输出结果是()。includeusing namespace std;void swap(int x[2]){int t; t=

    下面程序的输出结果是( )。 #include<iostream> using namespace std; void swap(int x[2]) { int t; t=x[0]; x[0]=x[1]; x[1]=t; } void main() { int a[2]={4,8}; swap(a); cout<<a[0]<<" "<<a[1]; }

    A.4 8

    B.8 4

    C.4 4

    D.8 8


    正确答案:B
    解析:数组名作为函数参数属于地址传递,形参、实参共用同一内存空间。

  • 第2题:

    下面程序的输出结果是()。include using namespace std;int fun (int, int);//fun ( )

    下面程序的输出结果是( )。 #include <iostream> using namespace std; int fun (int, int); //fun ( ) 函数的说明 void main( ) { int a =48,b =36,c; c = fun(a,B) ; cout<<c; } int fun(int u,int v) { int w; while (v) {w=u%v;u =v;v =w;} return u; }

    A.24

    B.12

    C.48

    D.36


    正确答案:B
    解析:注意运算符%的特点。

  • 第3题:

    以下程序的输出结果是( )。 include void swap(int*a,int*B){int*t; t=a;a=b;b=c;} main

    以下程序的输出结果是( )。 include<stdio.h> void swap(int*a,int*B){int*t; t=a;a=b;b=c;} main() {int i=3,j=5,*p=&i,*q=&j; swap(p,q);printf("%d %d\n",*p,*q); }


    正确答案:3 5
    3 5 解析:本题考查函数中形参和实参的传递。在C语言函数中实参和形参传递具有不可逆性,参数只能由实参传向形参,而不能由形参传向实参,虽然swap函数的功能是实现两个数的交换,但由于没有返回值,故最终的输出结果为3 5。

  • 第4题:

    如下程序的输出结果是includevoid fun(int & X,inty){intt=x;x=y;y=t;}int main(){in

    如下程序的输出结果是 #include<iostream> void fun(int & X,inty){intt=x;x=y;y=t;} int main( ){ int a[2]={23,42}; fun(a[1],a[0]); std::cout<<a[0]<<","<<a[1]<<std::endl; return 0; }

    A.42,42

    B.23,23

    C.23,42

    D.42,23


    正确答案:B
    解析:参数X是引用传递,传递的是地址:参数Y是值传递,函数fun( )是做X与Y值交换,交换后X的值要被回传给a[1],此时a[1]=a[0]=23。

  • 第5题:

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