问题 单项选择题

有以下程序:
#include <iostream>
using namespace std;
class sample

private:
int x;
public:
void setx(int i)

x=i;

int putx ()

return x;

;
int main ( )

sample *p;
sample A[3];
A[0] .setx(5);
A[1] .setx (6);
A[2] .setx(7);
for (int j=0;j<3;j++)

p=&A[j];
cout<<p->putx () <<", ";

cout<<end1;
return 0;

执行后执行结果是( )。

A.5,6,7,

B.5,5,5,

C.6,6,6,

D.7,7,7,

答案

参考答案:A

解析: 对象数组是指数组元素为对象的元素,该数组中的每一个元素都是同一个类的对象。程序中,定义了类sample的对象数组A,并调用各个对象的成员函数给其私有数据成员赋值。然后通过for循环将其值输出。

单项选择题
填空题