首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Test{ public: Test() {n+=2;} ~Test(){n-=3;) static im ge
有如下程序: #include using namespace std; class Test{ public: Test() {n+=2;} ~Test(){n-=3;) static im ge
admin
2012-12-29
14
问题
有如下程序:
#include
using namespace std;
class Test{
public:
Test() {n+=2;}
~Test(){n-=3;)
static im getNum(){return n;}
private:
staticintn;
};
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;会调用类的构造函数’rest(){n+=2;},使n的值由原来的1变为3,然后deletep调用类的析构函数~Test(){n-=3.},因为n是static型变量,所以会在3的基础上减3使得输出结果为0。
转载请注明原文地址:https://kaotiyun.com/show/s0Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中正确的是()。
设fp为指向某二进制文件的指针,且已读到此文件末尾,则函数feof(fp)的返回值为()。
有以下程序 #include<stdio.h> main() {charx,a=’A’,b=’B’,c=’C’,d=’D’; x=(a<B)a:b; x=(x>C)c:x; x=(d>x)x:d; printf(
设有定义:intk=3,i=2;以下选项中,变量k的值与其他三个不同的是()。
如图所示:带有头结点的单向链表head,其三个数据结点A、B、C的连接关系见图。 结点类型的定义为: structlink { doubledt; structlink*next; }; 若指针p指向A结点,在不改
C语言的逻辑表达式在特定情况下会产生“短路”现象。若有如下逻辑表达式: x++&&y++;则以下叙述中正确的是()。
软件按功能可以分为:应用软件、系统软件、支撑软件(或工具软件)。下面各项中属于应用软件的是()。
软件测试的目的是()。
【】的目的是检查模块是否正确的组合在一起,是否能够实现规格说明文档对产品功能的要求。
测试的,目的是暴露错误,评价程序的可靠性;而【】的目的是发现错误的位置并改正错误。
随机试题
给脊柱损伤的患者翻身时,下列哪几项是正确的()。
被狂犬咬伤后,对伤口的处理错误的是
男性,20岁,以头外伤2小时入院。入院查体:刺痛时可以睁眼,刺痛肢体回缩,言语不清。该患者GCS为
A.发热,盗汗,心前区疼痛少见,易转变为缩窄性心包炎B.心前区剧烈疼痛,有病毒感染史,能自愈C.血性心包积液,渗液抽出后又迅速产生D.高热,脓性心包积液E.心脏术后2周出现发热,胸痛,关节痛化脓性心包炎
用化肝煎加减治疗失笑散合丹参饮可治疗
在0.1mol/L的下列溶液中,说法正确的是()。
如托运人与承运人之间事先无货运协议或类似性质的任何协议,提单就是双方之间订立的运输合同。当托运人将提单通过背书方式转让给第三者时,提单就是承运人与第三者之间的合同。()
(2009年考试真题)W股份有限公司2008年有关资料如下:(1)1月1日部分总账及其所属明细账余额如表2—1—1所示:注:①该公未单独设置“预付账款”会计科目。②表中长期借款为2007年10月1日从银行借入,借款期限2年,年利率5%,每年付息一次。
下列博物馆中,与其类型一一对应正确的是()。
王国维(1877—1927)是我国近代著名的学者。他在《人间词话》中说:“古今之成大事业、大学问者,必经过三种之境界:‘昨夜西风凋碧树。独上高楼,望尽天涯路’。此第一境也;‘衣带渐宽终不悔,为伊消得人憔悴。’此第二境也;‘众里寻他千百度,蓦然回首,那人却在
最新回复
(
0
)