以下程序的输出结果是_____。 include<iostream.h> void fun( ) {static int a=0; a+=2;cout < <

题目
以下程序的输出结果是_____。 include void fun( ) {static int a=0; a+=2;cout < <

以下程序的输出结果是_____。

include<iostream.h>

void fun( )

{ static int a=0;

a+=2;

cout < < a < < " ";}

void main( )

{ int cc;

for(cc=1;cc<4;cc++)

fun( ) ;

cout < < endl;}

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序段的输出结果是includevoid fun(int*x,int*y){cout<<*x<<*y;*X=3;*y=4;}vo

下列程序段的输出结果是 #include<iostream.h> void fun(int*x,int*y) {cout<<*x<<*y; *X=3; *y=4; } void main() {int x=1,y=2; fun(&y,&x); cout<<X<<y<<endl; }

A.2143

B.1212

C.1234

D.2112


正确答案:A

第2题:

下列程序段的输出结果是includevoid fun(int * x,int * y){cout<<* X<<* y; *X=3;

下列程序段的输出结果是 #include<iostream.h> void fun(int * x,int * y) { cout << * X << * y; *X=3; *y=4; } void main() { int x=1,y=2; fun(&y,&x); cout << X << y<<endl; {

A.2143

B.1212

C.1234

D.2112


正确答案:A
解析:在fun函数中,x接收的是main函数中y的地址,所以*x值为2,同样,*y值为1,所以第1次输出的是21,第2次改变*x的值等同于改变y的值,改变*y的值也即改变x的值,所以第2次输出的是43。注意:C++语言中函数的传参方式中关于指针的应用。

第3题:

下列程序的输出结果是______。includeinclude using namespace std;void

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

include <iostream.h>

include <cstring.h>

using namespace std;

void fun(const char*s,char &C) {c=s[strlen (s)/2];}

int main {)

{

char str [] ="ABCDE";

char ch=str[1];

fun(str,sh);

cout<<Ch;

return 0;

}


正确答案:C
C 解析:本题考核数组的定义、使用以及函数的调用。fun函数的作用是将字符串str中间的字符赋值给地址传入的变量ch。所以ch的值将被修改为‘C’。

第4题:

以下程序的输出结果是【】。includevoid main() {int *p;p=new int;*p=200;cout<<*p;d

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

include<iostream. h>

void main() {

int *p;

p=new int;

*p=200;

cout<<*p;

delete p;

}


正确答案:200
200

第5题:

以下程序的输出结果是( )。 includefun(){ int a=0;a+=3;printf("%d",A); } main() {int

以下程序的输出结果是( )。

include<stdio.h>

fun()

{ int a=0;

a+=3;

printf("%d",A);

}

main()

{ int cc;

for(cc=1;cc<=4;cc++)

fun();

printf("\n");

}


正确答案:3 3 3 3
3 3 3 3 解析:本题考查for循环,for(cc=1;cc=4;cc++)表示循环4次,a+=3表示每次a的值增加3,但是子函数中没有将变量a定义为static类型,所以每次调用完子函数之后,变量a所做的改变都不能保存,这样在下一次调用子函数时,a的初值仍是0,所以不管调用多少次,子函数输出始终是3。

第6题:

以下程序的输出结果是【】。 include using namespace std; void fun() {static int a=0

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

include <iostream>

using namespace std;

void fun()

{

static int a=0;

a+=2;

cout<<a;

}

int main()

{

int CC;

for(CC=1;cc<4;CC++)

fun();

cout<<end1;

return 0;

}


正确答案:246
246 解析:本题考核函数调用和静态变量。在主函数中通过一个for循环调用了3次fun()函数。第1次调用fun()函数时,a的初始值为0,执行语句“a+=2;”后, a的值为2,输出2;第2次调用时,a的初始值为2,执行语句“a+=2;”后,a的值为4,最后输出4:第3次调用时,a的初始值为4,执行语句“a+=2:”后,a的值为6,最后输出6。

第7题:

以下程序的输出结果 ______。 include void main() { int a=0; a+ =(a=8); cout<

以下程序的输出结果 ______。

include<iostream.h>

void main()

{

int a=0;

a+ =(a=8);

cout<<a;

}


正确答案:16
16

第8题:

以下程序的输出结果是【】。 include void main( ) } int a=0; a+=(a=8); cout<

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

include<iostream.h>

void main( )

}

int a=0;

a+=(a=8) ;

cout<<a;

}


正确答案:16
16 解析:赋值表达式的值就是所赋值变量的值,本题中a+=8相当于a=a+8,对表达式逐步进行求解:a+=(a=8)此时,a的值由于赋值为8,而不是o
a+=8
a=a+8
a=16
注意: 要掌握“+=”等相关运算符的用法。

第9题:

下列程序的运行结果是()。include< iostream.h>void fun (int *a,int*b){int*kk=a;a=b;b=k}void

下列程序的运行结果是( )。 #include< iostream.h> void fun (int *a,int*b) {int*k k=a;a=b;b=k} void main() {int a=2004, b=9,*x=&a,*y=&b; fun(x, y) ; cout<<a<<" "<<b<<endl:}

A.20049

B.92004

C.0

D.编译时出错


正确答案:A