问题 单项选择题

下面程序的输出结果是
#include<iostream,h>
class example

int a;
public:
example(int b) a=b++;
void print( )a=a+1;cout<<a<<"";
void print( )constcout<<a<<"";
;
void main( )

example X(3);
const example y(2);
x.print( );
y.print( );

A.22

B.43

C.42

D.32

答案

参考答案:C

解析: “++”是右结合的,所以先赋值为3,最后输出3+1;常成员函数只有常对象才能调用,所以输出2。

单项选择题
填空题