下面程序的运行结果为( )。 #include<iostream.h> void swap(int &a,int B) { int temp; temp=a++; a=b; b=temp; } void

admin2010-12-16  39

问题 下面程序的运行结果为(    )。    #include<iostream.h>    void swap(int &a,int B) {    int temp;    temp=a++;    a=b;    b=temp;    }    void main()    {    int a=2,b=3;    swap(a,b);    cout<<a<<“,”<<b<<end1;    }   

选项 A、2,3     
B、3,2
C、2,2     
D、3,3

答案D

解析  本题考查的是引用调用,因为函数swap引用调用参数a,所以在swap函数中a的变化会改变主函数中 a的值,即a自加1,但b的值并未改变。
转载请注明原文地址:https://jikaoti.com/ti/25L0FFFM
0

相关试题推荐
随机试题
最新回复(0)