CC语言笔试面试题目含答案Word格式文档下载.docx
《CC语言笔试面试题目含答案Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《CC语言笔试面试题目含答案Word格式文档下载.docx(41页珍藏版)》请在冰豆网上搜索。
returnszIpAddr;
}
下面描述正确的是():
A、数组szIpAddr空间不够;
B、函数返回局部数组szIpAddr变量地址;
C、输出的IP地址次序颠倒;
5.
#defineOK0
#defineERR1
#defineERROR(-1)
#defineBUFFER_SIZE256
char*GetMemory(unsignedlongulSize)
char*pcBuf=NULL;
pcBuf=(char*)malloc(ulSize);
if(NULL==pcBuf)
returnERROR;
returnpcBuf;
voidTest(void)
char*pszBuf=NULL;
pszBuf=GetMemory(BUFFER_SIZE);
if(NULL!
=pszBuf)
strcpy(pszBuf,"
HelloWorld!
\r\n"
);
printf(pszBuf);
free(pszBuf);
如下描述正确的是:
A、pszBuf指向的内存不能超过255
B、GetMemory函数的异常分支返回了-1,是一个非法地址
C、GetMemory中异常分支没有释放空间;
D、pcBuf为局部指针,指向的内存将在GetMemory被调用后释放
6、#include"
"
unsignedshort*Sum(unsignedchara,unsignedcharb)
unsignedshorts=0;
s=a+b;
return&
s;
intmain()
unsignedshort*p=NULL;
unsignedchara=1,b=2;
p=Sum(a,b);
%u+%u"
a,b);
=%u\n"
*p);
return0;
程序执行结果是()
+2=0+2=3+2=NULLD.不可预测
7、设有如下定义:
BOOLgStatusA=FALSE;
BOOLgStatusB=TRUE;
intgVarA=100;
intgVarB=100;
则执行main函数后gVarA和gVarB的值分别为()
BOOLCheckA()
if(gStatusA)
gVarA++;
else
gVarA--;
returngStatusA;
BOOLCheckB()
if(gStatusB)
gVarB++;
gVarB--;
returngStatusB;
intmain(intargc,char*argv[])
if(CheckA()&
&
CheckB())
printf(“StatusOK”);
A,99和100B,99和101C99和99D101和99
8.下面的代码中,函数Test执行完毕后,希望输出无符号长整型的1。
voidVarInit(unsignedchar*pucArg)
*pucArg=1;
voidTest()
unsignedlongulGlobal;
VarInit(&
ulGlobal);
%lu"
ulGlobal);
下面描述正确的是:
A.给VarInit()函数传递的参数类型错误
()输出格式错误
C.传给VarInit()中参数pucArg的值为空指针
9、
voidAddFunc(unsignedinta,unsignedintb,unsignedint*c)
*c=a+b;
voidmain(void)
unsignedchare=200;
unsignedcharf=100;
unsignedcharg=0;
AddFunc((unsignedint)e,(unsignedint)f,(unsignedint*)&
g);
%d"
g);
下面说法正确的是():
A对g进行类型转换导致函数调用时写内存越界;
B对e、f进行类型转换导致函数调用时写内存越界;
C函数调用时不能改变g的值。
10、voidmain(void)
unsignedchara=200;
unsignedcharb=100;
unsignedcharc=0;
c=a+b;
%d%d"
a+b,c);
下列程序的执行结果为()
A300300
B4444
C30044
D44300
11、在X86,VC++环境下,有下列程序
#include<
charcA;
unsignedcharucB;
unsignedshortusC;
cA=128;
ucB=128;
usC=cA+ucB;
0x%x"
usC);
usC=cA+(short)ucB;
usC=(unsignedchar)cA+ucB;
usC=cA+(char)ucB;
输出结果是()
A)0x00x00x1000xff00
B)0x00x1000x1000xff00
C)0x00x1000x1000x0
D)0x00x00x1000x0
(c)中的c的数据类型可以是char、long、float、unsigned、bool.()
A.正确B.错误
Example()
inti;
characNew[20];
for(i=0;
i<
10;
i++)
acNew[i]='
0'
%d\n"
strlen(acNew));
的输出为()
A0B10C11D不确定
14.如下程序用于把"
blue"
字符串返回:
char*GetBlue(void)
char*pcColor;
char*pcNewColor;
pcColor="
pcNewColor=(char*)malloc(strlen(pcColor));
if(NULL==pcNewColor)
returnNULL;
strcpy(pcNewColor,pcColor);
returnpcNewColor;
A、字符串“blue”存放在栈内;
B、函数GetBlue返回局部变量地址;
C、内存空间分配长度不够,strcpy函数拷贝越界;
15.给出以下定义:
characX[]="
abcdefg"
characY[]={'
a'
'
b'
c'
d'
e'
f'
g'
};
则正确的叙述为()
A)数组acX和数组acY等价B)数组acX和数组acY的长度相同
C)数组acX的长度大于数组acY的长度D)数组acX的长度小于数组Y的长度
16.有以下程序段
characArr[]="
ABCDE"
char*pcPtr;
for(pcPtr=acArr;
pcPtr<
acArr+5;
pcPtr++)
%s\n"
pcPtr);
输出结果是()
A)ABCDB)AC)ED)ABCDE
BDBCDE
CCCDE
DBDE
EAE
Example()
characNew[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
的输出为:
18.如下程序用于把"
字符串打印出来:
voidPrintBlue()
charpcBlue[]={'
l'
u'
%s"
pcBlue);
A、pcBlue数组初始化时没有字符串结束符;
B、数组pcBlue定义时必须指明长度;
19.如下代码实现中,FuncA为每毫秒定时执行的函数,在该函数中,需要实现每TIME_INTERVAL毫秒执行一次DO_Something()的操作。
请指出段代码中的错误:
#defineULONGunsignedlong
#defineTIME_INTERVAL200
voidDoSomething(void)
/*....*/
voidFuncA()
staticULONGulPreCall=0;
ULONGulNowInMsHigh=0;
ULONGulNowInMsLow=0;
(VOID)VOS_Tm_Now(&
ulNowInMsHigh,&
ulNowInMsLow);
/*获取当前的时间,以毫秒为单位,用64bits表示,ulNowInMsHigh为高32位,ulNowInMsLow为低32位*/
if((0==ulPreCall)||(ulNowInMsLow>
=(ulPreCall+TIME_INTERVAL)))
ulPreCall=ulNowInMsLow;
return;
DoSomething();
A、函数FUNC_A第一次被调用时,不执行Do_Something()操作;
B、函数FUNC_A功能在一段时间后失效,因为ulNowInMsLow溢出翻转;
C、ulPreCall不应该定义为静态变量;
20、
#defineNULL0
#defineMEM_OK0
#defineMEM_ERR1
enumENUM_STAT_ITEM
STAT_ITEM0,
STAT_ITEM1,
STAT_ITEM_BUTT
typedefstructtag_PERM_COUNT_STAT_INFO
unsignedshortstat_item;
unsignedshortnumber;
}_SPermCountStatInfo;
_SPermCountStatInfopcsi[STAT_ITEM_BUTT]=
{STAT_ITEM0,16000},
{STAT_ITEM1,50000},
unsignedlong*pulStatDataBuffer=NULL;
unsignedshortAllocPermMemory(void)
unsignedshortusBufferSize=0;
unsignedshortusLoop=0;
for(usLoop=0;
usLoop<
STAT_ITEM_BUTT;
usLoop++)
usBufferSize+=pcsi[usLoop].number;
pulStatDataBuffer=(unsignedlong*)malloc(sizeof(unsignedlong)*usBufferSize);
if(NULL==pulStatDataBuffer)
returnMEM_ERR;
returnMEM_OK;
Aunsignedshort类型不能表示循环体中将16000与50000相加的和66000
B数组pcsi的number域是unsignedshort类型,不能表示50000这么大的数字
C循环条件应该改为usLoop<
=STAT_ITEM_BUTT
21.请指出下面这段代码中的错误:
unsignedlongFuncB(unsignedlongulCount)
unsignedlongulSum=0;
while(0<
=ulCount)
ulSum+=ulCount;
ulCount--;
returnulSum;
voidtest(void)
unsignedlongulTotal=0;
ulTotal=FuncB(10);
ulTotal);
A、while循环判断始终为真;
B、test打印输出55;
C、循环体内在执行2的32次方后,ulSum开始溢出翻转;
22.请指出下面程序的错误:
char*szStr=(char*)malloc(100);
if(NULL==szStr)
strcpy(szStr,"
free(szStr);
=szStr)
world"
szStr);
下面描述正确的是()
A、strcpy没有将结尾符拷贝到szStr中
B、对释放空间的指针进行拷贝操作
C、szStr被free后,szStr即为空。
23.#defineBUFFER_SIZE256
voidGetMemory(char**ppszBuf)
if(NULL==ppszBuf)
ASSERT(0);
*ppszBuf=(char*)malloc(BUFFER_SIZE);
char*pszBuf=NULL;
GetMemory(&
pszBuf);
helloworld\r\n"
pszBuf);
A、pszBuf的值永远为NULL;
B、malloc内存后没有判断是否成功;
C、strcpy拷贝越界;
D、GetMemory无法将申请的内存地址传递给pszBuf;
24、请问下面函数中1、2、3应该填入什么语句才合理?
A、不添,不添,不添
B、free(pMsg);
free(ptmpMsg);
不添
C、free(pMsg);
free(ptmpMsg);
D、不添,free(pMsg);
E、free(pMsg);
free(pMsg);
free(ptmpMsg);
F、不添,不添,free(ptmpMsg);
#defineCOMM_MSG_LEN100
char*GetMessageBuffer(intmalloc_len)
char*ptr=NULL;
ptr=(char*)malloc(malloc_len)
returnptr;
intFuncTest(void)
intmalloc_len=COMM_MSG_LEN;
char*pMsg=NULL;
char*ptmpMsg=NULL;
pMsg=GetMessageBuffer(malloc_len);
if(NULL==pMsg)
____1___
fillMessage(pMsg);
sendMessage(pMsg);
ptmpMsg=GetMessageBuffer(malloc_len);
if(NULL==ptmpMsg)
____2___
FillMessage(ptmpMsg);
SendMessage(ptmpMsg);
free(pMsg);
____3___
returnOK;
25.以下叙述中不正确的是()
A)在不同的函数中可以使用相同名字的变量
B)函数中的形式参数是在栈中保存
C)在一个函数内定义的变量只在本函数范围内有效
D)在一个函数内的复合语句中定义的变量在本函数范围内有效(复合语句指函数中的成对括号构成的代码)
26.全局变量可以定义在被多个.C文件包含着的头文件中。
27.在函数内部定义的变量(静态变量、寄存器变量等特殊变量除外)的内存是在栈内存中,所以在定义函数内部的变量的时候,一定要保证栈不能够溢出。
如果临时变量占用空间较大,应该使用内存申请的方式,这样该变量指向的内存就是在堆内存中了。
28.局部变量可以和全局变量重名,编译的时候不会出现错误,但一旦不小心,就可能导致使用错误变量,所以在定时局部变量的时候,不要和全局变量重名。
29.设有如下定义:
unsignedlongpulArray[]={6,7,8,9,10};
unsignedlong*pulPtr;
则下列程序段的输出结果为()
pulPtr=pulArray;
*(pulPtr+2)+=2;
printf("
%d,%d\n"
*pulPtr,*(pulPtr+2));
A)8,10B)6,8C)7,9D)6,10
30.structstu
{
intnum;
charname[10];
intage;
};
voidFun(structstu*p)
(*p).name);
structstustudents[3]={{9801,"
Zhang"
20},
{9802,"
Wang"
19},
{9803,"
Zhao"
18}};
Fun(students+2);
A)ZhangB)ZhaoC)WangD)18
31.以下程序运行后,输出结果是()
voidmain()
{
char*szStr="
abcde"
szStr+=2;
%lu\n"
AcdeB字符c的ASCLL码值
C"
这个常串中字符c所在的地址D出错
32.设有以下宏定义:
#defineN3
#defineY(n)((N+1)*n)/*这种定义在编程规范中是不允许的,如果你在实际中这么用了,请自打手心三下*/
则执行语句:
z=2*(N+Y(5+1));
后,z的值为()
A)出错B)42C)48D)54
33、有如下宏定义和结构定义
#defineMAX_SIZEA+B
struct_Record_Struct
unsignedcharEnv_Alarm_ID:
4;
unsignedcharpara1:
2;
unsignedcharstate;
unsignedcharavail:
1;
}*Env_Alarm_Record;
pointer=(struct_Record_Struct*)malloc(
sizeof(struct_Record_Struct)*MAX_SIZE);
当A=2,B=3时pointer分配()个字节的空间。
注意:
机器是按照4字节对齐
A)20B)15C)11