首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int
有如下程序: #include using namespace std; class Test{ public: Test() {n+=2;} ~Test() {n-=3;} static int
admin
2020-06-29
57
问题
有如下程序:
#include
using namespace std;
class Test{
public:
Test() {n+=2;}
~Test() {n-=3;}
static int getNum(){retum n;}
private:
static int n:
};
int Test::n=1;
int main()
{Test*p=new Test;
delete p;
cout<<"n="<
return 0:
}
执行后的输出结果是( )。
选项
A、n=0
B、n=1
C、n=2
D、n=3
答案
A
解析
语句Test*p=new Test;会调用类的构造函数1"est() {n+=2),使n的值由原来的1变为3,然后delete p调用类的析构函数~Test(){n-=3;},因为n是static型变量,所以会在3的基础上减3使得输出结果为0。
转载请注明原文地址:https://kaotiyun.com/show/rzyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下列标识符中,不属于文件流类的标识符是
有如下程序:#include#includeusingnamespacestd;classInstrument{public:Instrument
下列叙述中正确的是
下列关于模板的表述中,错误的是
下列关于默认参数的叙述中,错误的是
面向对象方法中,继承是指( )。
将E-R图转换为关系模式时,实体和联系都可以表示为( )。
设二叉树如下:则前序序列为
若MyClass是一个类名,且若MyClass是一个类名,且有如下语句序列MyClassc1,*c2;MyClass*c3=newMyClass;MyClass&c4=c1;上面的语句序列所定义的类对
有两个关系R和T如下:则由关系R得到关系T的操作是( )。
随机试题
妊娠末期,血清雌三醇值为非孕妇的________倍,雌二醇、雌酮为________倍。
A.M5aB.M5bC.两型D.小细胞为主E.大细胞为主
目前临床上何种细菌对青霉素耐药率最高
A、固化时收缩B、固化期15分钟C、固化期轻膨胀D、与牙齿有化学结合E、固化时体积无变化银汞合金
苦杏仁苷属于
投标文件中的大写金额和小写金额不一致的属细微偏差,修正此错误的原则是( )。
下列属于财务综合分析特点的有()。
关于民法上的物的表述,正确的是()。
设A为n阶实对称可逆矩阵,f(x1,x2,…,xn)=xixj.记x=(x1,x2,…,xn)T,把二次型f(x1,x2,…,xn)写成矩阵形式;
Cellscannotremainaliveoutsidecertainlimitsoftemperatureandmuchnarrowerlimitsmarktheboundariesofeffectivefunc
最新回复
(
0
)