首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class MyClass{ public: MyClass(){++count;} ~MyClass(){--count;}
有如下程序: #include using namespace std; class MyClass{ public: MyClass(){++count;} ~MyClass(){--count;}
admin
2020-04-07
50
问题
有如下程序:
#include
using namespace std;
class MyClass{
public:
MyClass(){++count;}
~MyClass(){--count;}
static int getCountO{return count;}
private:
static int count;
};
int MyClass::count=0;
int main(){
MyClass ohj;
cout<
MyClass*ptr=new MyClass;
cout<
delete ptr;
cout<
return 0;
}
程序的输出结果是( )。
选项
A、121
B、232
C、221
D、122
答案
A
解析
此题考查的是静态成员。静态成员的特性是不管这个类创建了多少对象,它的静态成员都只有一个拷贝副本,这个副本被所有属于这个类的对象共享。题目中,首先定义了obj对象,其构造函数使静态数据成员count增1,故输出“1”:然后通过指针动态创建了MyClass类的对象,构造函数被再次调用,count变为2,输出“2”;接着删除创建的MyClass类的对象,调用析构函数,count减1变为1,输出“1”。故最终输出结果是121。
转载请注明原文地址:https://kaotiyun.com/show/6R8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classDemopublic:{Demo(){cout<<"defaultconstruct
按照标识符的要求,开头的符号不能是()。
数据的存储结构是指()。
下面程序的输出结果是______。#include<iostream>usingnamespacestd;intx;voidfunA(int&,int);voidfunB(int,int&);int
在类中,______成员为类的所有对象所共享。
关于C++语言与C语言关系描述中错误的是
下列有关内联函数的叙述中,正确的是()。
以下选项中,合法的字符常量是()。
软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是()。A)学生成绩管理系统B)C语言编译程序C)UNIX操作系统D)数据库管理系统
两个或两个以上模块之间联系的紧密程度称为()。
随机试题
Studiesshowthatthethingsthatcontributemosttoasenseofhappinesscannotbebought,______agoodfamilylife,friendship
胃癌的主要转移途径是()
A.由胃肠粘膜分泌过多液体引起腹泻B.由肠内容物渗透压增高引的腹泻C.由肠粘膜的吸收面积减少引起咖泻D.由肠蠕动亢进,肠内食糜停留刚少所致的腹泻E.由某些致腹泻细菌内毒素刺激删膜内cAMP致腹泻上述腹泻的发病机制,属于
目前国际上主要有美国运通国际股份有限公司、大来信用证有限公司和中国银联三家专业信用卡公司。()
经初步核算,2009年上半年我国国内生产总值同比增长7.1%,比一季度加快1.0个百分点。其中,第一产业增加值12025亿元,增长3.8%;第二产业增加值70070亿元,增长6.6%;第三产业增加值57767亿元,增长8.3%。2009年上半年,我国国内生
属性BorderColor的作用是
Inthreecenturies-from1050to1350-severalmilliontonsofstonewerequarriedinFranceforthebuildingofeightycathedrals,
CityYhasinstalled30parkingmetersat15-footintervalsalongastraightstreet.Whatisthenumberoffeetbetweenthefirs
AlocaltelephonedirectoryissometimescalledtheYellowPages.Thisdirectoryprovidesanalphabetic(按字母顺序的)listingofnam
He______alettertoanInternetservicethatdistributesjournalists’questionstomorethan750institutions.
最新回复
(
0
)