#include <iostream>
using namespace std;
class base
{
int x;
public:
void setx( int a){x=a;}
int getx ( ){return x;}
} ;
void main ( )
{
int*p;
base a;
a.setx (15);
p= new int (a. getx(

程序分析题:阅读程序后,填写程序的正确运行结果。


#include <iostream>
using namespace std;
class base
{
int x;
public:
void setx( int a){x=a;}
int getx ( ){return x;}
} ;
void main ( )
{
int*p;
base a;
a.setx (15);
p= new int (a. getx( ));
cout < < * p;
}


【正确答案】:

15


【题目解析】:

只有产生类的对象,才能使用这些数据和成员函数。类不仅可以声明对象,还可以声明对象的引用和对象的指针,语法与基本数据类型一样。赋值15,因此输出结果为15。


Top