首页>计算机等级考试>历年真题>正文
常见c++笔试题整理(含答案)

www.zige365.com 2010-7-13 14:03:04 点击:发送给好友 和学友门交流一下 收藏到我的会员中心
, 因此只占一个字节但保存了两个信息, 该字节中第一位表示工
人的状态, 第二位表示工资是否已发放。由此可见使用位结构可以节省存贮空间。


--------------------------------------------------------------------------
22.
下面的函数实现在一个固定的数上加上一个数,有什么错误,改正
int add_n(int n)
{
static int i=100;
i+=n;
return i;
}

:
因为static使得i的值会保留上次的值。

去掉static就可了

--------------------------------------------------------------------------
23.
下面的代码有什么问题?
class A
{
public:
A() { p=this; }
~A() { if(p!=NULL) { delete p; p=NULL; } }

A* p;
};

:
会引起无限递归

--------------------------------------------------------------------------
24.
union a {
int a_int1;
double a_double;
int a_int2;
};

typedef struct
{
a a1;
char y;
} b;

class c
{
double c_double;
b b1;
a a2;

};

输出cout<<sizeof(c)<<endl;的结果?

:
VC6
环境下得出的结果是32

:
(sun)VC6.0+win2k下做过试验
:
short - 2
int-4
float-4
double-8
指针-4

sizeof(union),以结构里面size最大的为unionsize

----------------------------------------------------------------------------------

25.i最后等于多少?
int i = 1;
int j = i++;
if((i>j++) && (i++ == j)) i+=j;

:
i = 5

--------------------------------------------------------------------------
26.
unsigned short array[]={1,2,3,4,5,6,7};
int i = 3;
*(array + i) = ?

:
4

--------------------------------------------------------------------------
27.
class A
{
virtual void func1()

void func2();
}
Class B: class A
{
void func1(){cout << "fun1 in class B" << endl;}
virtual void func2(){cout << "fun2 in class B" << endl;}
}
A, A
中的func1B中的func2都是虚函数.
B, A
中的func1B中的func2都不是虚函数
.
C, A
中的func2是虚函数.B中的func1不是虚函数
.
D, A
中的func2不是虚函数,B中的func1是虚函数.

:
A

--------------------------------------------------------------------------
28.
数据库:抽出部门,平均工资,要求按部门的字符串顺序排序,不能含有"human resource"部门,

employee结构如下:employee_id, employee_name, depart_id,depart_name,wage

:
select depart_name, avg(wage)
from employee
where depart_name <> 'human resource'
group by depart_name
order by depart_name

--------------------------------------------------------------------------
29.
给定如下SQL数据库:Test(num INT(4)) 请用一条SQL语句返回num的最小值,但不许使用统计功能,如MINMAX

:
select top 1 num
from Test
order by num desc

--------------------------------------------------------------------------
30.
输出下面程序结果。

#include <iostream.h>

class A
{
public:
virtual void print(void)
{
    cout<<"A::print()"<<endl;
}
};
class B:public A
{
public:
virtual void print(void)
{
   cout<<"B::print()"<<endl;
};
};
class C:public B
{
public:
virtual void print(void)
{
   cout<<"C::print()"<<endl;
}
};
void print(A a)
{
   a.print();
}
void main(void)
{
   A a, *pa,*pb,*pc;
   B b;
   C c;
  
   pa=&a;
   pb=&b;
   pc=&c;
  

本新闻共15页,当前在第5页  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  

我要投稿 新闻来源: 编辑: 作者:
相关新闻