下列程序的执行结果是______。 include float temp; float&fn2(float r) { temp=下列程序的执行结果是______。include<iostream.h>float temp;float&fn2(float r){temp=r*r*3.14;return temp;}void main( ){float a=fn2(5.0);float&b=fn2(5.0);b=20;cout<<temp<<endl;}

题目
下列程序的执行结果是______。 include float temp; float&fn2(float r) { temp=

下列程序的执行结果是______。

include<iostream.h>

float temp;

float&fn2(float r)

{

temp=r*r*3.14;

return temp;

}

void main( )

{

float a=fn2(5.0);

float&b=fn2(5.0);

b=20;

cout<<temp<<endl;

}


相似考题
参考答案和解析
正确答案:20
20 解析:本题考察全局变量和引用的综合使用。在主函数中,b实际上是temp的一个引用。因此在给b赋值20的时候,输出的temp就是20。
更多“下列程序的执行结果是______。 include<iostream.h> float temp; float&amp;fn2(float r) { temp= ”相关问题
  • 第1题:

    有如下的程序: include include using namespace std; int main() { ofstr

    有如下的程序:

    include <iostream>

    include <fstream>

    using namespace std;

    int main()

    {

    ofstream outf("D:\\temp.txt",ios_base::trunc) ;

    outf<<"World Wide Web";

    outf.close();

    ifstream inf("D:\\temp.txt");

    char s[20];

    inf>>s;

    inf.close();

    cout<<s;

    return 0;

    }

    执行后的输出结果是【 】。


    正确答案:World
    World 解析:提取运算符>>在读取数据时遇到空格、Tab符号以及回车符时将结束此次相关操作。

  • 第2题:

    下面程序的结果为( )。 #include"iostream.h" void change(int a,int b) { int temp; temp=a; a=b b=temp; } void main() { int m,n; m=8; n=9; change(m,n); cout<<m<<" "<<n<<endl; }

    A.89

    B.98

    C.程序有错误

    D.99


    正确答案:A

  • 第3题:

    15、以下程序执行的结果是: my_dict={'bill':1,'rich':2,'fred':10,'walter':20} temp = 0 for value in my_dict.values(): temp = temp + value print (temp)


    33

  • 第4题:

    下面程序输出的结果为()。includevoid fun(int a,int b){int temp;temp=a;a=b;b=tem

    下面程序输出的结果为( )。 #include<iostream.h> void fun(int a,int b) { int temp; temp=a; a=b; b=temp; } void main() { int m,n; m=1; n=2; fun(m,n); cout<<m<<""<<n<<end1; }

    A.12

    B.21

    C.22

    D.程序有错误


    正确答案:A
    解析:函数fun中定义的参数a和b为形式参数,它们并不是实际存在的数据,只有在发生函数调用时才被分配内存空间,结束后,形参所占有的内存单元也被释放。并且函数fun没有返回值,它做的交换操作,并不能影响实际参数m和n。所以输出值保持不变,仍然是1和2,即输出:12。

  • 第5题:

    下面程序的运行结果为()。includevoid swap (int &a, int b){int temp;temp=a++

    下面程序的运行结果为( )。#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