首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面程序的结果为 #include<iostream.h> int c; class A { private: int a; static int b; public: A( )
下面程序的结果为 #include<iostream.h> int c; class A { private: int a; static int b; public: A( )
admin
2010-12-16
74
问题
下面程序的结果为
#include<iostream.h>
int c;
class A
{
private:
int a;
static int b;
public:
A( ) {a=0;c=0;}
void seta( ) {a++;}
void setb( ) {b++;}
void setc( ) {c++;}
void display( ) {cout < < a < < " " < < b < < " " < < c;}
};
int A: :b=0;
void main( )
{
A a1,a2;
a1.seta( ) ;
a1.setb( ) ;
al .setc( ) ;
a2.seta( ) ;
a2.setb( ) ;
a2.setc( ) ;
a2.display( ) ;
}
选项
A、1 2 1
B、1 2 2
C、1 1 2
D、2 2 2
答案
B
解析
C++语言中全局变量是任何函数都可以改变的量,静态变量的有效范围在定义它的类中,而普通的变量的有效性只在使用它的函数中,在本题中c为全局变量,b为静态变量,a为普通变量,b和c在类A的对象a1和s2中都自加1。所以b、c为 2,a为1。
转载请注明原文地址:https://www.kaotiyun.com/show/Y9Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序段#includemain(){inta,b,c;a=10;b=50;c=30;if(a>b)a=b,b=c;c=a;printf("a-=%db=%dc=%d\n",a,b,c)
下列定义变量的语句中错误的是()。
有以下程序:#include<stdio.h>main(){ intc=0,k; for(k=1;k<3;k++) switch(k) {default:c+=k;case2:c++;break;cas
数据独立性是数据库技术的重要特点之一。所谓数据独立性是指()。
以下程序的输出结果是()。#includemain()structst{p=aa;{intx;int*y;}*p;printf("%d\n",++(p->x));}
设有以下程序段floata[8]={1.0,2.0};intb[1]={0};charc[]={"A","B"};chard=="1";以下叙
若变量已正确定义并赋值,则以下符合C语言语法的表达式是()。
有以下程序:#includemain(){intc,d;c=13&5:d=10&&5;printf("%d,%d\n",c,d);}程序的运行结果是()。
数据库系统在其内部具有3级模式,用来描述数据库中全体数据的全局逻辑结构和特性的是()。
请编写函数fun,其功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。例如,若字符串数组中的M个字符串为{“AAAA”,“BBBBBBB”,“CC”},则合并后的字符串内容应该是“AAAABBBBBBBC
随机试题
对于睡眠呼吸暂停综合征的发病机制,不正确的是
作业在执行前完成地址转换,并在执行过程中不能移动位置的地址转换方式是_______。
LosAngeleshasplanted2,000rubbertreesdownthemiddleofoneofitsmainstreets.Thesetreesdonot【C1】______rubber.They
Cardiologistshavepioneeredtheworld’sfirstnon-surgicalbypassoperationtoturnaveinintoanarteryusinganewtechnique
能独立生活的最小微生物是()
下列不属于业主向承包商索赔的是()。
如果小明是2005年以前毕业的文学类硕士研究生,他就必须在硕士上学期间修满三年才能毕业。可推出以上论断的选项是()
下列对IPv6地址FF60:0:0:0601:BC:0:0:05D7的简化表示中,错误的是()。
Youshouldnotfearspidersthankstotheirpoison.Ofallthespidersin【M1】______NorthAmerica,onlyonekindisreallyda
A、Workershavetowalkupanddownalongtheassemblyline.B、Workersneedn’tmovewhiletheproduceismoved.C、Manypeopleacc
最新回复
(
0
)