首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
15
问题
有如下程序:
#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全国计算机二级
相关试题推荐
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。该工程中包含一个程序文件main.cpp,其中有“书”类Book及其派生出的“教材”类TeachingMaterial的定义,还有主函数main的定义。请在程序中“//*******
若已经定义了如下的函数:intf(inti,charc);则下列函数中可以作为此函数的重载函数的是
下列选项中,不是C++关键字的是
下列语句中错误的是
下列语句或语句序列中有语法错误的是
下列关于类定义的说法中,正确的是()。
软件生命周期是指( )。
支持子程序调用的数据结构是( )。
算法的时间复杂度是指()。
随机试题
在教育评价过程中,教育评定是()
患者,女,40岁。已婚,近1个月来无诱因出现情绪低落,晨重夜轻,对生活失去信心,食欲减退、精力下降,有自杀意念,睡眠差,有早醒,该患者最可能的诊断是
男性,40岁,体重60kg,烧伤总面积为60%,伤后第一个24小时所需补液量是
脑卒中最强的不可控性单一危险因素是()。
陈先生夫妇今年均已40岁,家里存款在50万元左右。他和妻子两个人每月收入大约1万元,月花费近4000元。陈先生和妻子计划在10年后退休,假设他们退休后再生存30年,且他们每年花费18万元(注:这笔钱在每年年初拿出),减掉基本养老保险和保险公司给予的保险金
北京阳光山谷马术俱乐部,位于朝阳区顺白鹭马泉营,会员数量居北京马术同行业之首。()
假设有以下C语言定义语句,表达式(31)不能正确引用值为7的数组元素。 int y[4][4]={1,2,3,4,5,6,7,8,9,10},*py1=y[1],(*py2)[4]=y;
Somepeoplefeelsadordepressedduringthewintermonthsinnorthernareasoftheworld.Theymayhavetroubleeatingorsleep
A、Nooneknowsforsurewhentheycameintobeing.B、Nooneknowsexactlywheretheywerefirstmade.C、Nooneknowsforwhatpu
An"applepolisher"isonewhogivesgiftstowinfriendshiporspecialtreatment.Itisnotexactlyabribe(贿赂),butiscloset
最新回复
(
0
)