首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){} sa
有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){} sa
admin
2013-02-27
36
问题
有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){} sample(int m) { n=m; sample add(sample s1,sample s2) { this->n=s1.n+s2.n; return (*this); void disp() cout<<"n="<<n<<end1; } int main() sample s1(10),s2(5),s3; s3.add(s1,s2); s3.disp(); return 0; 程序运行后,输出的结果是
选项
A、n=10
B、n=5
C、n=20
D、n=15
答案
8
解析
本题考核this指针的使用。类成员函数add中通过this指针实现私有数据成员n的赋值。
转载请注明原文地址:https://kaotiyun.com/show/svVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有语句:void*P=malloc(80);,则以下叙述错误的是()。
有以下程序 #include<stdio.h> int*fun() { staticinta[2]={0,1}; a[0]+=a[1]; a[1]+=a[0]; returna; } voidmain(
有以下程序 #include<stdio.h> intmul(intval) {staticintinit=l; returninit*=val: } main() {inti; for(i=l;i
有以下程序 #include<stdio.h> voidswap(int*a,int*b) {intt,*tp; t=*a;*a=*b;*b=t; tp=a;a=b;b=tp; printf("%d,%d,",*a,
以下程序拟调用getmax函数,找出四个变量中最大的一个,但程序不完整: #include<stdio.h> intgetmax(intx,inty) {returnx>yx:y;} voidmain() { inta,b,
请编写函数fun,其功能是:在一个含有11个四位数的数组中,统计出这些数的奇数、偶数个数,然后计算出个数多的那些数的算术平均值并由函数返回,个数通过yy传回。 例如,若11个数据为:1101,1202,1303,1404,1505,2611,2712,2
以下说法错误的是()。
下列说法正确的是()。
下面关于成员函数重载运算符和友元函数重载运算符相同的是()。
随机试题
Whatwillthemanprobablydo?
对德国民法典影响最大的法学派是()
已知二阶常系数齐次微分方程的通解为y=C1ex+C2e—x,则原方程为__________.
下列哪种疾病不易引起玻璃样变性
蛋白质营养不良可导致()含量下降。
女性患儿2岁,被诊断为流行性脑膜炎。
金银花中抗菌主要成分是()
手动火灾报警按钮安装在墙上距地(楼)面高度1.5m处。应安装牢固,并不得倾斜。按钮的外接导线,应留有( )以上的余量。
(2011国家30)过去的25年中,尽管经历着通货膨胀和经济衰退,美国人的消费能力始终没有减退,背后最主要的推力就是个人信贷业的异常_______,尽管个别客户可能破产,但总体上,个人消费信贷是________的。依次填入画横线部分最恰当的一项是:
DVD-ROM属于_______。
最新回复
(
0
)