1、阅读下面C++程序,分析程序的结果是( )
int main()
{
int a,b,c;
a=1, b=2, c=a+b+3;
cout << a << ", " << b << ", " << c << ", ";
c = (a++, a+=6, a+b);
cout << c << endl;
return 0;
}
A、1, 2, 6, 8
B、1, 2, 6, 9
C、1, 2, 6, 10
D、1, 2, 6, 11
E、编译出错
2、阅读下面C++程序,分析程序的结果是( )
void swap(int *pA, int *pB)
{
int temp;
temp = *pA;
*pA = *pB;
*pB = temp;
}
int main()
{
int x = 10, y = 20;
int *p, *q;
p = &x;
q = &y;
swap(*p,*q);
cout << x << endl;
cout << y << endl;
return 0;
}
A、10 20
B、20 10
C、值不确定
D、编译出错
3、阅读下面的C++程序,分析while循环执行的次数()
int main()
{
int x = -5;
while (x)
{
cout<< x++ << ",";
}
cout << endl;
return 0;
}
A、死循环,无限次
B、6次
C、5次
D、4次
5、在执行完下面语句后,指针c的值是( )
int a = 10, b = 20, *c=&a;
int *p=c;
p=&b;
A、a
B、b
C、c
D、p
6、下面程序执行后的输出结果是:
x=0,y=0
x=1,y=2
x=10,y=20
则在划线的地方应该填入的语句是:( )
#include
using namespace std;
class Sample
{
int x,y;
public:
Sample(){x=y=0;}
Sample(int a,int b){x=a;y=b;}
void disp()
{
void disp(){ cout<<"x="<<x<<",y="<<y<<endl; }
}
};
void main()
{
Sample s1,s2(1,2),s3(10,20);
for(int i=0;i<3;i++)
{
pa[i]->disp();
}
}
A、Sample *pa[3]={&s1,&s2,&s3};
B、Sample pa[3]={ s1, s2, s3};
C、Sample *pa[3]={*s1,*s2,*s3};
D、Sample pa[3]={&s1,&s2,&s3};
7、在C++中,Class是一个类,执行下面语句,将自动调用几次构造函数( )
Class a[3], *p[2];
A、2
B、3
C、4
D、5
8、阅读下面C++程序,分析程序的执行结果( )
class A
{
public:
int i;
void Print(){ cout << "In the A :" << i << endl; }
};
class B: public A
{
public:
void Print(){ cout << "In the B :" << i << endl; }
};
class C: public A
{
public:
C(){A::i = 10;}
int i;
void Print(){ cout << "In the C :" << i << ", " << A::i << endl; }
};
int main()
{
A a;
A* pa = &a;
B b, *pb;
C c, *pc;
c.i = 1 + (b.i = 1 + (a.i = 1));
pa->Print();
pb = &b;
pb->Print();
pc = &c;
pc->Print();
return 0;
}
A、编译出错
B、In the A :1
In the B :2
In the C :3, 10
C、In the A :1
In the B :2
In the C :10, 3
9、阅读下面C++程序,分析程序的执行结果( )
class A
{
private:
int a, b;
public:
A(int i, int j) { a=i; b=j; }
void move(int i, int j) { a+=i; b+=j; }
void disp(){ cout << "(" << a << ", " << b << ")" << endl; }
};
class B: public A
{
private:
int x, y;
public:
B(int i, int j, int k, int l):A(i,j), x(k), y(l){}
void disp(){ cout << x << ", " << y << endl; }
void fun(){ move(3, 5); }
};
int main()
{
A e(1, 2);
e.disp();
B d(3, 4, 5, 6);
d.fun();
d.A::disp();
d.disp();
return 0;
}
A、(1, 2)
(6, 9)
5, 6
B、(1, 2)
(8, 11)
3, 4
C、编译出错
10、阅读下面C++程序,分析程序的执行结果( )
class Sample
{
int x;
public:
Sample(int a)
{
x = a;
cout<< "Constructing object x = " << x << endl;
}
};
void func(int n)
{
static Sample obj(n);
}
int main()
{
func(1);
func(10);
return 0;
}
A、Constructing object x = 1
Constructing object x = 10
B、Constructing object x = 1
C、编译出错
电子邮箱:
*