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

www.zige365.com 2010-7-13 14:03:04 点击:发送给好友 和学友门交流一下 收藏到我的会员中心

   a.print();
   b.print();
   c.print();
  
   pa->print();
   pb->print();
   pc->print();
  
   print(a);
   print(b);
   print(c);
}

A:
A::print()
B::print()
C::print()
A::print()
B::print()
C::print()
A::print()
A::print()
A::print()

--------------------------------------------------------------------------
31.
试编写函数判断计算机的字节存储顺序是开序(little endian)还是降序(bigendian)

:
bool IsBigendian()
{
unsigned short usData = 0x1122;
unsigned char *pucData = (unsigned char*)&usData;

return (*pucData == 0x22);
}

--------------------------------------------------------------------------
32.
简述Critical SectionMutex的不同点

:
对几种同步对象的总结

1.Critical Section
A.
速度快
B.
不能用于不同进程
C.
不能进行资源统计(每次只可以有一个线程对共享资源进行存取)

2.Mutex
A.
速度慢
B.
可用于不同进程
C.
不能进行资源统计

3.Semaphore
A.
速度慢
B.
可用于不同进程
C.
可进行资源统计(可以让一个或超过一个线程对共享资源进行存取)

4.Event
A.
速度慢
B.
可用于不同进程
C.
可进行资源统计

--------------------------------------------------------------------------
33.
一个数据库中有两个表:
一张表为Customer,含字段
ID,Name;
一张表为Order,含字段ID,CustomerID(连向CustomerID的外键),Revenue

写出求每个CustomerRevenue总和的SQL语句。

建表
create table customer
(
ID int primary key,Name char(10)
)

go

create table [order]
(
ID int primary key,CustomerID int foreign key references customer(id) , Revenue float
)

go

--查询
select Customer.ID, sum( isnull([Order].Revenue,0) )
from customer full join [order]
on( [order].customerid=customer.id )
group by customer.id

--------------------------------------------------------------------------
34.
请指出下列程序中的错误并且修改
void GetMemory(char *p){
p=(char *)malloc(100);
}
void Test(void){
char *str=NULL;
GetMemory=(str);
strcpy(str,"hello world");
printf(str);
}

A:错误--参数的值改变后,不会传回
GetMemory
并不能传递动态内存,Test函数中的 str一直都是 NULL
strcpy(str, "hello world");
将使程序崩溃。

修改如下:
char *GetMemory(){
char *p=(char *)malloc(100);
return p;
}
void Test(void){
char *str=NULL;
str=GetMemory(){
strcpy(str,"hello world");
printf(str);
}

方法二:void GetMemory2(char **p)变为二级指针.
void GetMemory2(char **p, int num)
{
*p = (char *)malloc(sizeof(char) * num);
}

--------------------------------------------------------------------------
35.
程序改错
class mml
{
private:
    static unsigned int x;
public:
    mml(){ x++; }
    mml(static unsigned int &) {x++;}
    ~mml{x--;}
pulic:
    virtual mon() {} = 0;
    static unsigned int mmc(){return x;}
    ......                     

};
class nnl:public mml
{
private:
    static unsigned int y;
public:
    nnl(){ x++; }
    nnl(static unsigned int &) {x++;}
    ~nnl{x--;}

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

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