首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Test{ public: Test(){n+=2;} ~Test(){n-=3;} static int getNum(){return n;} p
有如下程序: #include<iostream> using namespace std; class Test{ public: Test(){n+=2;} ~Test(){n-=3;} static int getNum(){return n;} p
admin
2019-04-01
36
问题
有如下程序:
#include<iostream>
using namespace std;
class Test{
public:
Test(){n+=2;}
~Test(){n-=3;}
static int getNum(){return n;}
private:
static int n;
};
int Test::n=1;
int main()
{
Test*p=new Test;
delete p;
cout<<"n="<<Test::getNum()<<endl;
return0:
}
执行后的输出结果是( )。
选项
A、n=0
B、n=1
C、n=2
D、n=3
答案
A
解析
语句Test*p=new Test;会调用类的构造函数Test() {n+=2;},使n的值由原来的1变为3,然后delete p调用类的析构函数~Test() {n-=3;},因为n是static型变量,所以会在3的基础上减3使得输出结果为0。
转载请注明原文地址:https://kaotiyun.com/show/caAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的运行结果为______。#include<iostream.h>voidmain(){inti;for(i=1;i<6;i++)if(i==3)break;cout<<
对n个元素的序列进行冒泡排序时,最少的比较次数是______。
在公有派生情况下,有关派生类对象和基类对象的关系,下列叙述不正确的是
类的析构函数的作用是
已知一棵二叉树前序遍历和中序遍历分别为ABDEGCFH和DBGEACHF,则该二叉树的后序遍历为
有以下程序:#include<iostream>usingnamespacestd;classMyClass{public:MyClass();~MyClass();staticints;
树中度为零的结点称为______。
下面程序的输出结果是()。#include<iostream.h>Classexample{inta;public:example(intB.{a=b++;}voidprint(){a=a+1
下面程序的运行结果为()。#include(iostream.h)ClassA{public:A(){cout<<“1”;}~A(){cout<<“2”;}};ClassB:public:
一棵二叉树第6层(根结点为第一层)的结点最多为______个。
随机试题
股票可以通过依法转让而变现的特性是指股票的()。
Theeconomymaybetroubled,butoneareaisthriving:socialmedia.TheybeginwithFacebookandextendthroughadizzyingarra
某人的肺通气量为7500ml/min,呼吸频率为20次/min,无效腔气量为125ml,每分心输出量为5000ml时,其通气/血流比值应是
男,60岁,高血压病史近20年,经检查:心室肌肥厚,血压:22.6/13.3kPa。最好选用哪种降压药
旧桥梁拆除施工专家论证应考虑()等方面的问题。
下列关于可撤销民事行为被撤销后的结果的论述中,错误的是()。
一般资料:男,16岁,高一学生。案例介绍:求助者性格内向。在父亲严格的管教下,养成了做事认真、追求完美的习惯,母亲很宠爱求助者,对其照顾无微不至,因此求助者很依赖母亲。求助者的学习成绩一直很好,考上了现在这所重点高中。但是离家比较远,需要寄宿在学
Writeanessaybasedonthechartbelow.Inyourwriting,youshould1)interpretthechart,and2)giveyourcomments.
模块设计中常用的衡量指标是内聚和耦合,内聚程度最高的是(1);耦合程度最低的是(2)。(2)
Theworldhasexperienced【L1】______urbangrowthintherecentdecades.Asmuchas3%ofEarth’s【L2】______hasbeenurbanized,a
最新回复
(
0
)