首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n: public: sample(int i) { n=i; } static void
若有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n: public: sample(int i) { n=i; } static void
admin
2020-11-11
31
问题
若有如下程序:
#include<iostream>
using namespace std;
int s=0;
class sample
{
static int n:
public:
sample(int i)
{
n=i;
}
static void add()
{
s+=n;
}
};
int sample::n=0:
int main()
{
samplea(2),b(5);
sample::add();
cout<<s<<endl:
return0:
}
程序运行后的输出结果是( )。
选项
A、2
B、5
C、7
D、3
答案
B
解析
执行语句“sample a(2),b(5)”;的结果是使n的值最终变为5,sample::add()语句调用函数static void add(),使得S=S+n=5。
转载请注明原文地址:https://kaotiyun.com/show/2ayp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中正确的是()。
有如下程序:#include<iostream>usingnamespacestd;classA{public:A(){cout<<"A";}~A(){cout<<"~A":}};classB:publicA{A*p;pu
有如下程序:#include<iostream>classA{public:A(intn=2):m_i(n){}~A(){std::cout<<m_i;}protected:intm_i;};classB:publicA{
下面程序的运行结果为()。#include<iostream.h>voidmain(){for(inta=0,x=0;!x&&a<=10;a++){a++;}cout<<a<<endl;}
下列关于C++类的叙述中,错误的是()。
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:Number=8注意:错误的语句在∥********error********的下面,修改该语句即可。#includecl
下列有关运算符重载的叙述中,正确的是
对于语句cout<<endl<<x;中的各个组成部分,下列叙述中错误的是
若实体A和B是一对多的联系,实体B和C是一对一的联系,则实体A和C的联系是
程序流程图中带有箭头的线段表示的是
随机试题
汉语中的动态助词“了”只能用于过去时。()
Inthesamewaythatachildmustbeabletomovehisarmsandlegsbeforehecanlearntowalk,thechildmustphysiologically
肾虚型产后身痛的首选方剂为肾阴亏虚型产后小便淋痛的首选方剂为
通过椎旁静脉系统发生转移的是
根据《建设工程施工合同(示范文本)》(GF一1999一0201),如果干扰事件对工程的影响持续时间长,承包则应按工程师(监理人)要求的合理间隔,提交中间索赔报告,并在干扰事件影响结束后的()天提交一份最终索赔报告。
增值税一般纳税人购进的下列服务中进项税额不能从销项税额中抵扣的有()。
自学作为一种培训方式,其优点不包括()。
高校课程的纵向结构包括普通教育课程、基础课程、________和专业课程。
A、Manystudentscan’tgetupdatedonlineinformation.B、Manystudentsdonotmakethemostuseofprintedbooks.C、Manystudents
A、ConveniencesbroughttoconsumersthroughtheuseoftheInternet.B、ImplicationsoftheincreasingcommercialuseoftheInte
最新回复
(
0
)