CC语言笔试面试题目含答案.docx

上传人:b****6 文档编号:16780561 上传时间:2023-07-17 格式:DOCX 页数:50 大小:27KB
下载 相关 举报
CC语言笔试面试题目含答案.docx_第1页
第1页 / 共50页
CC语言笔试面试题目含答案.docx_第2页
第2页 / 共50页
CC语言笔试面试题目含答案.docx_第3页
第3页 / 共50页
CC语言笔试面试题目含答案.docx_第4页
第4页 / 共50页
CC语言笔试面试题目含答案.docx_第5页
第5页 / 共50页
CC语言笔试面试题目含答案.docx_第6页
第6页 / 共50页
CC语言笔试面试题目含答案.docx_第7页
第7页 / 共50页
CC语言笔试面试题目含答案.docx_第8页
第8页 / 共50页
CC语言笔试面试题目含答案.docx_第9页
第9页 / 共50页
CC语言笔试面试题目含答案.docx_第10页
第10页 / 共50页
CC语言笔试面试题目含答案.docx_第11页
第11页 / 共50页
CC语言笔试面试题目含答案.docx_第12页
第12页 / 共50页
CC语言笔试面试题目含答案.docx_第13页
第13页 / 共50页
CC语言笔试面试题目含答案.docx_第14页
第14页 / 共50页
CC语言笔试面试题目含答案.docx_第15页
第15页 / 共50页
CC语言笔试面试题目含答案.docx_第16页
第16页 / 共50页
CC语言笔试面试题目含答案.docx_第17页
第17页 / 共50页
CC语言笔试面试题目含答案.docx_第18页
第18页 / 共50页
CC语言笔试面试题目含答案.docx_第19页
第19页 / 共50页
CC语言笔试面试题目含答案.docx_第20页
第20页 / 共50页
亲,该文档总共50页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

CC语言笔试面试题目含答案.docx

《CC语言笔试面试题目含答案.docx》由会员分享,可在线阅读,更多相关《CC语言笔试面试题目含答案.docx(50页珍藏版)》请在冰点文库上搜索。

CC语言笔试面试题目含答案.docx

CC语言笔试面试题目含答案

C语言试题

一:

单项选择题

1.

voidExample(characHello[])

{

printf("%d",sizeof(acHello));

return;

}

voidmain()

{

characHello[]="hello";

Example(acHello);

return;

}

的输出是()

A4B5C6D不确定

2.网络上传输的字节序默认是大字节的,如果主机是小字节序,在网络通信时则须进行字节序转换;如果主机是大字节序,为了程序的一致性及可移植性,最好也在程序中加上字节序转换的操作(空操作)。

()

A.正确B.错误

3.int*(*ptr)();

则以下叙述中正确的是()

A)ptr是指向一维组数的指针变量

B)ptr是指向int型数据的指针变量

C)ptr是指向函数的指针,该函数返回一个int型数据

D)ptr是指向函数的指针,该函数的返回值是指向int型数据的指针

4.此函数实现把32位IP地址(网络序)以字符串的方式打印出来:

char*IpAddr2Str(unsignedlongulIpAddr)

{

charszIpAddr[32];

unsignedlongulLocIpAddr=ntohl(ulIpAddr);//把网络序转话为主机序

(void)VOS_sprintf(szIpAddr,"%d.%d.%d.%d",ulLocIpAddr>>24,

(ulLocIpAddr>>16)&0xff,(ulLocIpAddr>>8)&0xff,ulLocIpAddr&0xff);

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);

}

return;

}

如下描述正确的是:

A、pszBuf指向的内存不能超过255

B、GetMemory函数的异常分支返回了-1,是一个非法地址

C、GetMemory中异常分支没有释放空间;

D、pcBuf为局部指针,指向的内存将在GetMemory被调用后释放

6、#include"stdio.h"

unsignedshort*Sum(unsignedchara,unsignedcharb)

{

unsignedshorts=0;

s=a+b;

return&s;

}

intmain()

{

unsignedshort*p=NULL;

unsignedchara=1,b=2;

p=Sum(a,b);

printf("%u+%u",a,b);

printf("=%u\n",*p);

return0;

}

程序执行结果是()

A.1+2=0B.1+2=3C.1+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++;

}

else

{

gVarB--;

}

returngStatusB;

}

intmain(intargc,char*argv[])

{

if(CheckA()&&CheckB())

{

printf(“StatusOK”);

}

return0;

}

A,99和100B,99和101C99和99D101和99

8.下面的代码中,函数Test执行完毕后,希望输出无符号长整型的1。

voidVarInit(unsignedchar*pucArg)

{

*pucArg=1;

return;

}

voidTest()

{

unsignedlongulGlobal;

VarInit(&ulGlobal);

printf("%lu",ulGlobal);

return;

}

下面描述正确的是:

()

A.给VarInit()函数传递的参数类型错误

B.printf()输出格式错误

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);

printf("%d",g);

}

下面说法正确的是():

A对g进行类型转换导致函数调用时写内存越界;

B对e、f进行类型转换导致函数调用时写内存越界;

C函数调用时不能改变g的值。

10、voidmain(void)

{

unsignedchara=200;

unsignedcharb=100;

unsignedcharc=0;

c=a+b;

printf("%d%d",a+b,c);

}

下列程序的执行结果为()

A300300

B4444

C30044

D44300

11、在X86,VC++6.0环境下,有下列程序

#include

intmain()

{

charcA;

unsignedcharucB;

unsignedshortusC;

cA=128;

ucB=128;

usC=cA+ucB;

printf("0x%x",usC);

usC=cA+(short)ucB;

printf("0x%x",usC);

usC=(unsignedchar)cA+ucB;

printf("0x%x",usC);

usC=cA+(char)ucB;

printf("0x%x",usC);

return0;

}

输出结果是()

A)0x00x00x1000xff00

B)0x00x1000x1000xff00

C)0x00x1000x1000x0

D)0x00x00x1000x0

12.switch(c)中的c的数据类型可以是char、long、float、unsigned、bool.()

A.正确B.错误

13.voidExample()

{

inti;

characNew[20];

for(i=0;i<10;i++)

{

acNew[i]='0';

}

printf("%d\n",strlen(acNew));

return;

}

的输出为()

A0B10C11D不确定

14.如下程序用于把"blue"字符串返回:

char*GetBlue(void)

{

char*pcColor;

char*pcNewColor;

pcColor="blue";

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

{

printf("%s\n",pcPtr);

}

return;

输出结果是()

A)ABCDB)AC)ED)ABCDE

BDBCDE

CCCDE

DBDE

EAE

17.voidExample()

{

inti;

characNew[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

for(i=0;i<10;i++)

{

acNew[i]='0';

}

printf("%d\n",strlen(acNew));

return;

}

的输出为:

()

A0B10C11D不确定

18.如下程序用于把"blue"字符串打印出来:

voidPrintBlue()

{

charpcBlue[]={'b','l','u','e'};

printf("%s",pcBlue);

return;

}

下面描述正确的是():

A、pcBlue数组初始化时没有字符串结束符;

B、数组pcBlue定义时必须指明长度;

19.如下代码实现中,FuncA为每毫秒定时执行的函数,在该函数中,需要实现每TIME_INTERVAL毫秒执行一次DO_Something()的操作。

请指出段代码中的错误:

#defineULONGunsignedlong

#defineTIME_INTERVAL200

voidDoSomething(void)

{

/*....*/

return;

}

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;

}

else

{

return;

}

DoSomething();

return;

}

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

{

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);

printf("%lu",ulTotal);

}

下面描述正确的是():

A、while循环判断始终为真;

B、test打印输出55;

C、循环体内在执行2的32次方后,ulSum开始溢出翻转;

22.请指出下面程序的错误:

voidTest(void)

{

char*szStr=(char*)malloc(100);

if(NULL==szStr)

{

return;

}

strcpy(szStr,"hello");

free(szStr);

if(NULL!

=szStr)

{

strcpy(szStr,"world");

printf("%s",szStr);

}

return;

}

下面描述正确的是()

A、strcpy没有将结尾符拷贝到szStr中

B、对释放空间的指针进行拷贝操作

C、szStr被free后,szStr即为空。

23.#defineBUFFER_SIZE256

voidGetMemory(char**ppszBuf)

{

if(NULL==ppszBuf)

{

ASSERT(0);

return;

}

*ppszBuf=(char*)malloc(BUFFER_SIZE);

return;

}

voidTest(void)

{

char*pszBuf=NULL;

GetMemory(&pszBuf); 

strcpy(pszBuf,"helloworld\r\n");

printf("%s",pszBuf);

free(pszBuf);

return;

}

下面说法正确的是():

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);,free(ptmpMsg);

D、不添,free(pMsg);,free(ptmpMsg);

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___

returnERROR;

}

fillMessage(pMsg);

sendMessage(pMsg);

ptmpMsg=GetMessageBuffer(malloc_len);

if(NULL==ptmpMsg)

{

____2___

returnERROR;

}

FillMessage(ptmpMsg);

SendMessage(ptmpMsg);

free(pMsg);

____3___

returnOK;

}

25.以下叙述中不正确的是()

A)在不同的函数中可以使用相同名字的变量

B)函数中的形式参数是在栈中保存

C)在一个函数内定义的变量只在本函数范围内有效

D)在一个函数内的复合语句中定义的变量在本函数范围内有效(复合语句指函数中的成对括号构成的代码)

26.全局变量可以定义在被多个.C文件包含着的头文件中。

()

A.正确B.错误

27.在函数内部定义的变量(静态变量、寄存器变量等特殊变量除外)的内存是在栈内存中,所以在定义函数内部的变量的时候,一定要保证栈不能够溢出。

如果临时变量占用空间较大,应该使用内存申请的方式,这样该变量指向的内存就是在堆内存中了。

()

A.正确B.错误

28.局部变量可以和全局变量重名,编译的时候不会出现错误,但一旦不小心,就可能导致使用错误变量,所以在定时局部变量的时候,不要和全局变量重名。

()

A.正确B.错误

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)

{

printf("%s\n",(*p).name);

return;

}

voidmain()

{

structstustudents[3]={{9801,"Zhang",20},

{9802,"Wang",19},

{9803,"Zhao",18}};

Fun(students+2);

return;

}

输出结果是()

A)ZhangB)ZhaoC)WangD)18

31.以下程序运行后,输出结果是()

voidmain()

{

char*szStr="abcde";

szStr+=2;

printf("%lu\n",szStr);

return;

}

AcdeB字符c的ASCLL码值

C"abcde"这个常串中字符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(

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2