首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
根据输出结果填空完成下面程序。 #include<iostream.h> class Test { private: static int val; int a; public: st
根据输出结果填空完成下面程序。 #include<iostream.h> class Test { private: static int val; int a; public: st
admin
2010-12-16
49
问题
根据输出结果填空完成下面程序。
#include<iostream.h>
class Test
{
private:
static int val;
int a;
public:
static int func( );
void sfunc(Test &r);
};
______//初始化静态变量val
int Test::func( )
{
return val++;
}
void Test::sfunc(Test &r)
{
r.a=125;
cout<<"Result3="<<r.a;
}
void main( )
{
cout<<"Resultl="<<Test::func( )<<endl;
Test A;
cout<<"Result2="<<A.fune( )<<endl;
A. sfunc(A);
}
输出结果为:
Result1=201
Result2=202
Result3=125
选项
答案
int Test::val=200;
解析
类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。
转载请注明原文地址:https://kaotiyun.com/show/N9Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#includemain(){inta[4][4]={{1,4,3,2},{8,6,5,7},{3,7,2,5},{4,8,6,1}};inti,j,k,t;
下列程序的运行结果是()。#includevoidfun(int*s,int*P){staticintt:3;*p=s[t];t--;}voidmain()
有以下程序:#include<stdio.h>main(){inti,array[6]={1,5,0,4};for(i=0;i<5;i++)printf("%d",array[i]);printf("\n");}程序运行后的输出结果是(
大学中每个年级有多个班,每个班有多名学生,则实体班级和实体学生之间的联系是()。
若a、b、c、d都是int型变量且都已经正确赋初值,则以下不正确的赋值语句是()。
下列方法中,不属于软件调试方法的是()。
程序流程图中带有箭头的线段表示的是()。
下列各排序算法中,最坏情况下的时间复杂度最低的是()。
检查软件产品是否符合需求定义的过程称为()。
多态性分为两类:编译时的多态性和【】。
随机试题
Onceuponatimeapoorfarmertakingasackofwheattothemill.Hedidnotknow【56】todowhenitslippedfromhishorseandf
按照编制现金流量表的要求,不列入现金流入的项目是()。
多层单栋住宅的长度大于()时应设4m宽、4m高的消防车通道。
各类金融机构的同一类型业务统一由一个监管机构监管,不同类型业务由不同监管机构分别监管,这种模式为()。
34,36,35,18,(),9,37,()
2014年1-10月我国货物运输总量为多少亿吨?()
文艺复兴时期,成功塑造了一个典型的没落骑士的小说是()。
实践是人类能动地改造世界的客观物质性活动。实践的基本形式有
Toddwasworkingathisgasstationatnightwhenheheardovertheradiothata(16)inLongIslandhadbeen(17)byana
Flexibilityisanessentialcomponentofgoodcooking.Youshouldneverfeellockedintoarecipeoramenuunlessitinvolvesa
最新回复
(
0
)