首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
以下程序的执行结果为( )。 #inc1ude<iostream.h> c1ass Samp1e { int n; public: Samp1e(int i){n=i;} operator++0
以下程序的执行结果为( )。 #inc1ude<iostream.h> c1ass Samp1e { int n; public: Samp1e(int i){n=i;} operator++0
admin
2019-04-18
36
问题
以下程序的执行结果为( )。
#inc1ude<iostream.h>
c1ass Samp1e
{
int n;
public:
Samp1e(int i){n=i;}
operator++0{n++;} //前缀重载运算符
operator++(int){n+=2;} //后缀重载运算符
void disp()
{
cout<<"n="<<n<<end1;
}
};
void main()
{
Samp1e A(2),B(2);
A++:
++B;
A.disp();
B.disp();
}
选项
A、n=4 n=3
B、n=1 n=2
C、n—3 n=4
D、n=5 n=6
答案
A
解析
此题考查的是“++”运算符的重载。为了区分前缀和后缀运算符,规定:重载后缀运算符时必须多一个虚拟参数:int。本题中,A(2)首先给n赋值2,语句AH,调用的是后缀运算符重载语句,使得n加2变为4。B(2)首先给n赋值2,然后语句++B,调用前缀运算符重载函数,使得n加l。因此最终的输出结果是n=4 n=3。
转载请注明原文地址:https://kaotiyun.com/show/z4Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的运行结果是()。#include<iostream.h>classA{inta;public:A(){a=0;}A(){intaa}{a=aa;cout<<a++
下列程序的输出结果为2,请将程序补充完整。#include<iostream>usingnamespaeestd;classBase{public:______voidfun(){cout<<1
C++中只有两个逻辑常量:true和______。
在结构化分析使用的数据流图(DFD)中,利用______对其中的图形元素进行确切解释。
在数据库系统中,实现各种数据管理功能的核心软件称为______。
下列关于this指针的叙述中,正确的是
数据的存储结构是指
有如下程序:#include<iostream>usingnamespacestd;classGrandChild{public:GrandChild(){strcpy(name,"Unknown"
下列数据结构中,能用二分法进行查找的是
静态数据成员在()进行初始化。
随机试题
Angecandedealtwithindifferentways.Togetabettersenseofwhatmakesyoumad【C1】______ajournalofsituationsthatmake
缺铁性贫血所致外胚叶营养障碍有以下何种表现
血糖来源的叙述中不正确的是
混合支持式义齿受力后,颌力由()
在城市总体布局中,对城市居民的劳动组织有很大影响的是()。
市场预期理论认为()。
混合销售行为应当征收营业税的,营业额为应税劳务营业额与货物销售额的合计。()
Inthedebateovergenetically-alteredfoods,proponentsNikeSenatorRichardLugararguedthatsuchproductswillbeessential
InJulyof1994,anastoundingseriesofeventstook(31).Theworldanxiouslywatchedas,everyfewhours,ahurtlingchunkof
WhatdoesSaffronwanttobeinthefuture?
最新回复
(
0
)