下面的程序输出的结果是( )。 #include <iostream> using namespace std; void main(){

题目
下面的程序输出的结果是( )。 include using namespace std; void main(){

下面的程序输出的结果是( )。 #include <iostream> using namespace std; void main(){ int a=2; int &c=a; a++; cout<<c; }

A.2

B.3

C.4

D.*a

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

第1题:

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

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

include<iostream.h>

include<string.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,ch);

cout<<ch;

return 0;

}


正确答案:C
C

第2题:

程序的输出结果是【 】。 include using namespace std; class A{ int x; public: A(int

程序的输出结果是【 】。

include <iostream>

using namespace std;

class A{

int x;

public:

A(int x=1):x(x){cout<<x;}

};

void main(){

A a,b(2),c(3);

}


正确答案:123
123 解析:a对象使用和默认的构造函数,b对象使用2来初始化对象c对象使用3来初始化对象,输出相应的值后,结果变为123。

第3题:

以下程序的输出结果是【】。 include using namespace std; int main() {char S[]="abcde

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

include <iostream>

using namespace std;

int main()

{

char S[ ]="abcdef";

s[3]='\0';

cout<<s<<end1;

return 0;

}


正确答案:abc
abc 解析:字符串的结束标记是'\0',当输出一个存放在字符数组中的字符串时,只需输出到'\0'为止,而不管其后还有什么数据。本题给字符数组s的元素s[3]赋值'\0',故只能输出3个字符“abc”。

第4题:

下列程序的输出结果是【】。 include using namespace std; int main(){int data=1;int

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

include <iostream>

using namespace std;

int main()

{

int data=1;

int &r = data;

data+=5;

r+=5;

cout<<data<<end 1;

return 0;

}


正确答案:11
11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后data的值为11。

第5题:

程序的输出结果是【 】。 include using namespace std; class A{ public: A(){a=b=2;}

程序的输出结果是【 】。

include <iostream>

using namespace std;

class A{

public:

A(){a=b=2;}

A(int i,int j){a=i;b=j;}

void display(){cout<<a<<b;}

private:

int a,b;

};

void main(){

A m,n(4,8);

m.display();

n.display();

}


正确答案:2248
2248 解析:m对象使用和默认的构造函数,其a与b变量的值均为2;而n变量使用4和8来初始化程序的变量,a,b的值为4和8,依次输出的结果为2248。

第6题:

下面程序运行后输出的结果是【】。 include using namespace std; class example{ const

下面程序运行后输出的结果是【 】。

include <iostream>

using namespace std;

class example{

const int m;

public:

example(int i):m(i){}

void pr(){cout<<"m="<<m<<endl'}

};

int main(){

example x(100);

x.pr();

return 0;

}


正确答案:m=100
m=100 解析:在类example中,定义了一个常数据成员m,所以构造函数只能通过初始化列表来初始化它。

第7题:

下面程序的执行结果是______。 include include using namespace std; vo

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

include<iostream.h>

include<iomanip.h>

using namespace std;

void main()

{

cout<<setfill('x')<<setw(10);

cout<<"Hello"<<endl;

}


正确答案:xxxxxHello
xxxxxHello 解析:本题考核I/O的格式化输出。setfill('x')表示填充字符为'x',并且一直有效,直到再次设置填充字符为止。setw(10)表示将输入输出宽度设置为10,当实际数据宽度小于指定的宽度时,多余的位置用填充字符填满;当实际数据的宽度大于设置的宽度时,仍按实际的宽度输出。宽度设置的效果只对一次输入或输出有效,在完成一个数据的输入或输出后,宽度设置自动恢复为0(表示按数据实际宽度输入输出)。题中字符串“Hello”的宽度不够10,所以其前面将有5个填充符 'x'。

第8题:

如下程序的输出结果是______。 include using namespace std; class pumpkin{ publ

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

include<iostream>

using namespace std;

class pumpkin{

public:

pumpkin( ){++count;}

~pumpkin( ){--eount;}

static void total_count( ){cout<<count<<"pumpkin(s)"<<endl;}

private:

static int count;

};

int pumpkin::count=0;

int main( ){

pumpkin pl[10];

pumpkin::total_count( );

return 0;

}


正确答案:10pumpkin(s)
10pumpkin(s) 解析:在主函数中pumpkin pl[10];定义了一个有10个元素的对象数组,所以调用了10次构造函数,静态数据成员court累加了10次,pumpkin::total_count( );显式调用类成员函数,直接调用静态成员函数:total_count( ),打印pumpkin(s)。

第9题:

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

第10题:

下列程序的输出结果是______。 include using namespace std; void fun(int &rf) {

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

include<iostream>

using namespace std;

void fun(int &rf)

{

rf*=2;

}

int main()

{

int num=500;

fun(num);

cout<<num<<endl;

return 0;

}


正确答案:1000
1000 解析:本题考核引用作为函数参数的使用。引用作为形参时,它实际上就是实参,函数对形参的访问和修改就是对实参的访问和修改,题中函数fun对形参的操作是自增2倍,所以经过函数调用后,实参的值自增2倍,即输出1000。

更多相关问题