首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如下程序的输出结果是 #include<iostream> using namespace std; class Test{ public: Test( ){n+=2;} ~Test( ){n-=3;} stati
如下程序的输出结果是 #include<iostream> using namespace std; class Test{ public: Test( ){n+=2;} ~Test( ){n-=3;} stati
admin
2013-05-30
37
问题
如下程序的输出结果是 #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: delete P; cout<<"n="<<Test::getNum( )<<endl; return 0; }
选项
A、n=0
B、n=1
C、n=2
D、 n=3
答案
A
解析
静态数据成员的初始值n=1,执行Test*p=new Test;,调用构造函数后,n= 3,deletep;调用析构函数,n-=3,所以最终n=0。
转载请注明原文地址:https://kaotiyun.com/show/VnNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
C++提供的【】机制允许一个派生类继承多个基类,即使这些基类是相互无关的。
设inta=10,b=11,c=12;,表达式(a/b)<c&&b==c的值是【】。
若有如下程序:#include<iostream>usingnamespacesstd;ints=0;classsample{staticintn;public:sample(inti){n=i;}staticvoidadd(){
下列程序的运行结果是()。#include<iostream.h>voidfun(int*a,int*b) {int*k;k=a;a=b;b=k;}voidmain(){inta=2OO4,b=9,*x=&a,*y=&b;fu
关于二义性的描述错误的是()。
类模板的使用实际上是将类模板实例化成一个具体的()。
下面程序的输出结果为【】。#include<iostream.h>f(inta){intb=0;staticintc=3;b++;c++;return(a+b+c);}voidmain(){inta=2,i;
MyClock类的拷贝构造函数的声明语句为()。
有如下程序:#include<iostream>usingnamespacestd;intfun(inta,intb){return(++a*b++);}voidmain(){
if语句的语法格式可描述为:格式1:if(<条件>)<语句>或格式2:if(<条件>)<语句1>else<语句2>关于上面的语法格式,下列表述中错误的是()。
随机试题
组织形象的基本特性主要有()
______hecanrecoversoon,Idon’tmindhowmuchmoneyIhavetopay.
轻度睡眠呼吸暂停综合征,其呼吸暂停指数范围是
庙底沟类型的彩陶艺术的代表作是()。
台历:墙壁
关于人民检察院对审判活动的监督,错误的是()。
简述情绪和情感的成分。
改革开放首先从农村开始,家庭联产承包责任制确定包产到户的原则,改变了()
Yougothereinordertoseeaplay.Youuseittokeeprainoffyourhead.
Completethetablebelow.WriteNOMORETHANTWOWORDSAND/ORANUMBERforeachanswer.
最新回复
(
0
)