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

admin2009-02-15  40

问题 下面程序的运行结果为    #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

答案8

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

最新回复(0)