首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2; } ~Test() {n-=3;
有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2; } ~Test() {n-=3;
admin
2013-02-27
23
问题
有如下程序: #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的运算具有叠加性,执行“n+=2”和“n-=3”后n的值为0。
转载请注明原文地址:https://jikaoti.com/ti/hCL0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设有如下类型说明语句 typedefstruct {intnum; struct{inty,m,d;}date; }PER; 则以下定义结构体数组并赋初值的语句中错误的是()。
有以下结构体说明、变量定义和赋值语句: structSTD{charname[10];intage;charsex;}s[5],*ps;ps=&s[0]; 则下列scanf函数调用语句有错误的是()。
有以下程序 #include<stdio.h> int*fun() { staticinta[2]={0,1}; a[0]+=a[1]; a[1]+=a[0]; returna; } voidmain(
有以下程序 #include<stdio.h> main() {inta[3][3]={{1,3,5,}, {7,9,11,}, {13,15,17}}; int(*p)[3]=a,i,j,n=0; f
某系统结构图如下图所示,该系统结构图的最大扇入数是()。
设栈的顺序存储空间为S(1:m),初始状态为top=0。现经过一系列正常的入栈与退栈操作后,top=m+1,则栈中的元素个数为()。
若有定义语句:intx=10;,则表达式x-=x+x的值为()。
若有定义:doublea;floatb;shortc;若想把1.2输入给变量a,3.4输入给变量b,5678输入给变量c,程序运行时键盘输入: 1.23.45678<回车> 则以下正确的读入语句是()。
下列给定程序中,函数fun的功能是:将主函数中两个变量的值进行交换。例如,若变量a中的值为8,b中的值为3,则程序运行后,a中的值为3,b中的值为8。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序
定义部门的关系模式如下: 部门(部门号,部门名,部门成员,部门总经理) 使它不满足第一范式的属性是()。
随机试题
一次指数平滑预测法中,a代表的是平滑系数,其取值范围是()
排便感由下列哪种原因引起
对肝硬化呕血患者的正确护理措施是
患者,男,40岁。体检中发现抗一HIV阳性,CD4T细胞0.7×109/L,总淋巴细胞数2.0×109/L,外周血HIV载量500copies/m1,患者无任何症状。目前治疗正确的处理方法是
《高层民用建筑设计防火规范》(GB50045—1995)(2001年修订版)中规定:防烟分区内的排烟口距最远点的水平距离不应超过()mm。
企业发生的下列费用中,应计入存货成本的有()。
自行研究开发无形资产的企业,开发过程中发生的费用符合资本化条件的,应()。
有一个健康教育工作者正在设计一项研究,其目的是在于对六所城市中学生的饮食习惯进行调查。饮食习惯涉及这样的一些因素,如学生吃喝什么东西、什么时候进食等。假设决定使用访谈法对学生中的随机样本进行访谈,请为该访谈设计3~4个样题。你如何核对是否有粗心的或不诚实的
下列叙述中错误的是()。
______madehisnameasagreatpoetwiththepublicationofAnEssayonCriticismin1711.
最新回复
(
0
)