首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
20
问题
有如下程序:
#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://kaotiyun.com/show/qC8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的执行结果是【】。#include<iostream.h>voidmain(){cout.fill(’*’);cout.width(10);cout<<123.45<<endl;cout
以下4个选项中,属于浮点数常量的是()。
类ostream的成员函数【】用于执行无格式输出,成员函数put用于输出单个字符。
以下程序的执行结果是_____。#include<iostream.h>#include<iomanip.h>voidmain(){cout.fill(’*’);cout.width(10);
在类的定义中,用于为对象分配内存空间,对类的数据成员进行初始化并执行其他内部管理操作的函数是
软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是()。A)学生成绩管理系统B)C语言编译程序C)UNIX操作系统D)数据库管理系统
下列关于队列的叙述中,正确的是()。
通常拷贝构造函数的参数是
C++中的类有两种用法:一种是类的实例比,即生成类的对象,并参与系统的运行;另一种是通过()派生出新的类。
______是数据库设计的核心。
随机试题
已知齐次线性方程组有非零解,则λ的值为______.
下个月将有来自60个国家的2000多名青少年来本市参加“Robocup2007”(2007世界机器人足球赛)。校学生会计划成立一个120人的志愿者(volunteer)团队。请你写一篇征求志愿者的通知。内容包括;1.征求志愿者的原因:
血站实验室质量体系文件中,关于仪器、设备的维护和使用,说法不正确的是
维生素D缺乏性手足搐搦症在小婴儿中最常见的症状是
患者,男,57岁,症见脘腹胀痛,下痢赤白,里急后重,舌苔黄腻,脉沉实者。治宜选用
数据的离散程度与代表性的关系是()。
某校毕业生分为9个班,每班人数相等。已知一班男生比二、三班女生总数多1。四、五、六班三个班的女生总数比七、八、九班三个班的男生总数多1,那么该校毕业生中男、女人数比是()。
一、注意事项 1.申论考试,与传统作文考试不同,是对分析驾驭材料的能力与对表达能力并重的考试。 2.作答参考时限:阅读资料40分钟,作答110分钟。 3.仔细阅读给定的资料,按照后面提出的“申论要求”依次作答。二、给定资料(1)
为了避免流程图在描述程序逻辑时的灵活性,提出了用方框图来代替传统的程序流程图,通常也把这种图称为()。
PassageThree(1)Oncethepreserveofmonastic(修道院的)retreatsandhardcoremeditators,simplybeingquietisgrowingina
最新回复
(
0
)