首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面程序的运行结果是( )。 #include using namespace std; class TestClass { static int n; public: TestClass 0
下面程序的运行结果是( )。 #include using namespace std; class TestClass { static int n; public: TestClass 0
admin
2020-10-21
24
问题
下面程序的运行结果是( )。
#include
using namespace std;
class TestClass
{
static int n;
public:
TestClass 0
{
n++;
}
static int test()
{
for(int i=0;i<4;i++)
n++:
return n:
}
};
int TestClass::n=0;
int main()
{
cout<
TestClass el,c2;
cout<
return 0;
}
选项
A、4,10
B、4,6
C、0,6
D、0,4
答案
A
解析
在主函数中首先调用TestClass中的test函数输出,类中的n为静态数据成员,可以为所有的对象共享这些数据,这里调用后n等于4。定义对象c1,c2调用构造函数后n=6,所以主函数再次执行“cout<
转载请注明原文地址:https://kaotiyun.com/show/xVyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespaeestd;classA{public:A(){eout
有如下程序:#includeusingnamespacestd;classPoint{public:Point(intxx,intyy):x(xx),y(yy){}intGetxy()
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)类CBase有一个常数变量Number1,在构造函数时对其初始化,请在注释//********1********后
已知枚举类型定义语句为:enumToken{NAME,NUMBER,PLUS=5,MINUS,PRINT=10};则下列叙述中错误的是()。A枚举常量NAME的值为1,B枚举常量NUMBER的则下列叙述中错误的是()。
静态数据成员是为()的数据。
使用VC6打开考生文件夹下的源程序文件modi3.cpp,要求编写一个CMyShape类,含有求面积求周长等纯虚函数。然后编写一个CMyRectangle类和CMyCircle类继承CMyShape,并实现求面积、求周长的两个函数。在main()函数中测试
下面关于算法的叙述中,正确的是()。
在C++语言中函数返回值的类型是由()决定的。
数据库设计中反映用户对数据要求的模式是()。
在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是()。
随机试题
毛泽东在《关于正确处理人民内部矛盾的问题》中,提出的处理国家、生产单位和生产者个人关系的方针是
急性酒精中毒应用纳洛酮的作用是
老贾在德裕商场购得由腾飞公司生产的热水器一台,一周后,贾妻在家使用时,热水器突然起火爆炸,将贾妻烧伤。经鉴定,事故的原因为该热水器不符合现有的国家标准,系产品缺陷。老贾和德裕商场就赔偿协商未果,现准备通过法律手段解决。试回答以下各题:现法院认定产品缺
在检查建设工程的实体质量中不包括的内容是()。
2011年2月10曰,某建设单位领取了施工许可证。由于某种原因,工程不能按期开工。根据我国《建筑法》的规定,申请延期应在()前进行。
如图,在平面直角坐标系中,点A,B的坐标分别为(一3,0),(0,6).动点P从点O出发,沿x轴正方向以每秒1个单位的速度运动,同时动点C从B出发,沿射线BO方向以每秒2个单位的速度运动,以CP,CO为邻边构造COD,在线段OP延长线上取点E,使PE=AO
公文行文制度的核心是()。
MTV:音乐电视
毛泽东提出调动一切积极因素建设社会主义强国思想的著作是()。
Ifyouknowwhatthetroubleis,whydon’tyouhelpthemto______thesituation?
最新回复
(
0
)