c语言笔试题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.填空题

(1)、请写出下列代码的输出内容

#include

int main(void)

{

int a,b,c,d;

a=10;

b=a++;

c=++a;

d=10*a++;

printf("b,c,d:%d,%d,%d",b,c,d);

return 0;

}

答:10,12,120

(2) char str[] = "\\\0";

char *p = str;

int n = 1000;

请计算

sizeof (str ) =____________

sizeof ( p ) =______________

sizeof ( n ) = ______________

3 4 4

(3) UCHAR *pucCharArray[10][10];

typedef union unRec

{

ULONG ulIndex;

USHORT usLevel[6];

UCHAR ucPos;

}REC_S;

REC_S stMax,*pstMax;

四字节对齐方式时:sizeof(pucCharArray) = ______, sizeof(stMax)=_______, sizeof(pstMax)=________,sizeof(*pstMax)=________.

400 12 4 12

(4) struct BBB

{

long lNum;

char *pcName;

short sDate;

char cHa[2];

short sBa[6];

}*p;

p = 0x100000;

p + 0x1 = 0x____

(unsigned long)p + 0x1 = 0x______

(unsigned long *)p + 0x1 = 0x______

(char *)p + 0x1 = 0x______

100018 100001 100004 100001

(5)struct tagAAA

{

unsigned char ucId:1;

unsigned char ucPara0:2;

unsigned char ucState:6;

unsigned char ucTail:4;

unsigned char ucAvail;

unsigned char ucTail2:4;

unsigned long ulData;

}AAA_S;

问:AAA_S在字节对齐分别为1、4的情况下,占用的空间大小是多少?

9 12

(6)#pragma pack(4)/*编译选项,表示4字节对齐*/

int main(int argc, char* argv[])

{

struct tagTest1

{

short a;

char d;

long b;

long c;

};

struct tagTest2

{

long b;

short c;

char d;

long a;

};

struct tagTest3

{

short c;

char d;

long a;

};

struct tagTest1 stT1;

struct tagTest2 stT2;

struct tagTest3 stT3;

printf("%d %d %d", sizeof(stT1), sizeof(stT2), sizeof(stT3));

return 0;

}

#pragma pack()(编译选项结束)

请问输出结果是:_________

12 12 16

(7)enum ENUM_A

{

X1=2,

Y1,

Z1 = 6,

A1,

B1

};

enum ENUM_A enumA = Y1;

enum ENUM_A enumB = B1;

请问enumA = ____; enumB = ______;

3 8

(8)以下程序的输出结果是________.

#include

int fun(int x,int y)

{

static int m = 0;

static int i = 2;

i += m + 1;

m = i + x + y;

return m;

}

void main()

{

int j = 4;

int m = 1;

k = fun(j, m);

printf("%d,", k);

k=fun(j, m);

printf("%d\n", k);

return;

}

8 17

(9)以下程序的输出结果为________

#define CIR(r) r*r /*请注意这种定义的缺陷,不允许这么定义*/

void main()

{

int a = 1;

int b = 2;

int t;

t = CIR(a + b);

printf("%d\n", t);

return;

}

5

(10)struct tagABC

{

char cB;

short sC;

char cD;

long lA;

}*pAbc;

pAbc = 0x100000;

那么pAbc+0x100 = 0x_________; (ULONG)pAbc + 0x100 = 0x_________;(ULONG *)pAbc + 0x100 = 0x_________;(char *)pAbc + 0x100 = 0x_______;

100C00 100100 100400 100400

2.改错题

(1)下面程序把"hello"这个字符串输出,请指出其中的错误。

void Test(void)

{

char pcArray[10];

strncpy(pcArray,"hello",5);

相关文档
最新文档