首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Test{ public: Test() {n+=2;} -TestO {n-=3;} s
有如下程序: #include<iostream> using namespace std; class Test{ public: Test() {n+=2;} -TestO {n-=3;} s
admin
2020-04-07
23
问题
有如下程序:
#include<iostream>
using namespace std;
class Test{
public:
Test() {n+=2;}
-TestO {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()<<end1;
return 0;
}
执行后的输出结果是( )。
选项
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://jikaoti.com/ti/4GA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列关于this指针的叙述中,正确的是______。
设x和y均为bool量,则x||Y为假的条件是______。
若运行时给变量x输入12,则以下程序的运行结果是#include<iostream.h>voidmain(){intx,y;cin>>x;y=X>12?x+10:x-12;cout
表达式x.operator+(y.operator++(0))还可以写成【】。
下列关于C++与C语言的关系的描述中,()是错误的。
将7个数据进行插入排序,在最坏情况下需要比较的次数是
运算符重载是对已有的运算符赋予多重的含义,所以()。
将运算符重载为类成员函数时,其参数表中没有参数,说明该运算符是
完全不考虑程序的内部结构和内部特征,而只是根据程序功能导出测试用例的测试方法是
随机试题
(2010年04月)北京奥运会某场比赛的门票以座位所在区位不同,价格分别为880元,680元,480元,280元,180元不等。该定价策略属于差别定价策略,具体为_________。
随着植入滋养层分化为两层,外层为________滋养层,内层为________滋养层。
中毒性细菌性菌痢的肠道病变有
始动外源性凝血途径的凝血因子是
关于气体灭菌养护技术描述不正确的是()。
下列属于境外投资重点支持项目正确的是()。
账套建立后,企业可以根据业务需要对某些已经设定的参数内容进行修改。如果账套参数内容已被使用,进行修改可能会造成数据的紊乱,因此,对账套参数的修改应当谨慎。()
2014年5月,境外公司为我国A企业提供系统支持、咨询服务,合同价款200万元,该境外公司在该地区有代理人,则该代理人应当扣缴的增值税税额为()。(2014年)
简述遗产的特征。
2006年10月份,“国房景气指数”为103.40,比9月份上升0.26点,比2005年10月份上升2.38点。房地产开发投资分类指数为101.68,比9月份下降0.04点,比2005年10月份上升0.82点。2006年1~10月,全国完成
最新回复
(
0
)