首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){}
有以下程序: #include<iostream> using namespace std; class sample { private: int n; public: sample(){}
admin
2010-03-29
38
问题
有以下程序: #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/6Djp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列关于栈的叙述中,正确的是()。
有以下程序#includevoidmain(){intn=2,k=-1;while(!(k>0‖n++));printf("%d%d\n",k,n);}程序运行后的输出结果是(
有以下程序#include<stdio.h>voidfun(int*s,intt,int*k){intp;for(p=0,*k=p;p<t;p++)if(s[p]>s[*k])*k
下列给定程序中,函数fun的功能是:输出M×M整数方阵,然后求两条对角线上元素之和,并作为函数值返回。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdli
有以下程序:#include<stdio.h>intfun(inta,intb){if(b==0)returna;elsereturn(fun(--a,--b));}main(){printf("%d\n",fun(4,2));}程
下列叙述中正确的是
数据流图中带有箭头的线段表示的是()。
设R是一个2元关系,有3个元组,S是一个3元关系,有3个元组。如T=R×S,则T的元组的个数为()。
数据流图中带有箭头的线段表示的是( )。
以下选项中不能作为C语言合法常量的是()。
随机试题
当事人申请仲裁须满足什么条件?
“人心不同,各如其面”反映的人格特点是
某工程在订立施工合同中,双方协商一致采用仲裁的方式处理合同纠纷,则关于仲裁协议说法错误的有()。
“格物、致知、诚意、正心、修身、齐家、治国、平天下”出自于()。
教育学史上,首次从科学认识的角度强调并试图探讨教育理论的教育家是()
Whenpeoplebecomeaging,theywilllosesomeoftheirabilitytobouncebackfromdiseaseandinjury,"bounceback"heremeans
WhyWouldTheyFalselyConfess?Whyonearthwouldaninnocentpersonfalselyconfesstocommittingacrime?Tomostpeople,it
Researchershaveestablishedthatwhenpeoplearementallyengaged,biochemicalchangesoccurinthebrainthatallowittoact
WhenIwasachild,myfamilyusedtogoonholidayeveryyeartovisitourrelativesinthenorth-eastofEngland.Oneofthem
A、Becausethemountainisover12,000feethigh.B、Becausehehadnoexperiencesinceheleftcollege.C、Becausehiswifewasn’t
最新回复
(
0
)