首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; Class Test { public: Test() {n+=2;} ~Test() {n-=3;} sta
有如下程序: #include<iostream> using namespace std; Class Test { public: Test() {n+=2;} ~Test() {n-=3;} sta
admin
2010-12-16
31
问题
有如下程序: #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;
选项
A、n=0
B、n=1
C、n=2
D、n=3
答案
A
解析
静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题中变量n是静态数据成员,对象对其操作的结果具有叠加作用,main函数中先定义了Test的对象*p,然后又delete p,所以对静态数据n进行了两次操作,分别是”n+=2”和”n+=3”,n的初始值是1,那么n最后的值变为0。main函数最后通过调用静态函数getNum得到n的值,并输出。
转载请注明原文地址:https://kaotiyun.com/show/v6Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设变量均已正确定义,若要通过scanf(’’%d%c%d%c’’,&a1,&c1,&a2,&c2);语句为变量a1和a2赋数值10和20,为变量c1和c2赋字符x和y。以下所示的输入形式中正确的是()。(注:□代表空格
下面4个关于C语言的结论中错误的是()。
有以下程序#includeintm1(intx,inty){returnx
设有定义:chars[81];inti=0;以下不能将一行(不超过80个字符)带有空格的字符串正确读入的语句或语句组是()。
以下程序的输出结果是()。#inc1udemain(){inta=1,b—3;if(++a
设有以下函数:voidfun(intn,char*s){……}则下面对函数指针的定义和赋值均是正确的是()。
若有函数首部intfun(doublex[10],int*n),则下列针对此函数的函数声明语句中正确的是()。
对于某个函数调用,不给出调用函数的声明的情况是()。
随机试题
提高劳动职业技能是劳动者的义务。
婴儿对食物味道非常敏感,适宜添加辅食的时期是
A.精神呆滞B.频繁惊厥C.腹痛D.颈强直E.面神经瘫痪结核性脑膜炎早期主要表现
与强直性脊柱炎有关的HLA基因型主要是
外感热病中,正邪相争,提示病变发展转折点的是()
秦艽的功效是
耕地占用税的特点有()。
甲企业与乙银行签订借款合同,借款金额为100万元人民币,借款期限为1年,由丙企业作为借款保证人。合同签订3个月后,甲企业因扩大生产规模急需追加资金,遂与乙银行协商,在未经丙同意的情形下,将贷款金额增加到150万元。后甲企业到期不能偿还债务,下列关于丙企业保
每一个复杂的生物个体都是由各种不同的细胞构成的系统,其中每个细胞中的DNA都包含了该生物个体所有性状的遗传信息。这段话蕴涵的哲理有()。
公众的“有色眼镜”,经常________、由点到面:而公共部门的形象,也是一荣俱荣、一损俱损。只有认识到了这一点,我们才能把对各种公平和不公平怀疑的回应,当作重建信任的一环,并以此积累信任、________诚信社会。填入画横线部分最恰当的一项是:
最新回复
(
0
)