image

编辑人: 舍溪插画

calendar2025-03-19

message4

visits438

博大正方C语言参考试题

1.头文件中的 ifndef/define/endif 有什么作用?

 

2.#include  <filename.h>   和  #include  “filename.h” 有什么区别?

 

3.请说明const 的用途。(至少两种)

 

4.请指出其区别:

const char* p:

char const *p:

char* const p:

5.请说明continue和break的用途。

 

6.请说明assert的用途。

 

7.指出下面类型分别在32位系统64位系统下所占的位数:

32位系统:

char:  short int  long void *

 

64位系统:

char:  short int  long void*

 

8.写出下面操作的结果(所有变量均为整数):

a.表达式(a = 2, b = 5, b ++, a + b)的结果:

b.表达式(a = 2, b = 5, ++ b, a + b)的结果:

 

9.请指出下面那种类型的变量不能用于switch语句:

char, unsigned char, long, float, double

10. 写出下面程序片的执行结果:

10.1(联合与位域)

union

{

struct {

unsigned int x1:2;

unsigned int x2:3;

unsigned int x3:3;

}x;

char y;

}z;

z.y = 100;

z.x.x3的值为___

 

10.2 (switch语句和break)

int n, x = 5;

switch(x){

case 5: n = 5;

case 6: n = 6;

default: n = -1;

}

则 n = __;

 

10.3 (运算符优先级)

char high, low, word;

low = 5;

high = 10

word = high << 3 + low ;

则word = _____

 

10.4(数据溢出)

char x = 119;

char y = 83;

char z = x + y;

则z的值____

 

10.5 (指针数组)

int a[3][4], (*p)[4];

p = a;

则*p+1指向____。

 

10.6以下为Windows NT下的32位C程序,请计算sizeof的值

char  str[] = “Hello” ;

char   *p = str ;

int     n = 10;

请计算

sizeof (str ) =_____

sizeof ( p ) =_____

sizeof ( n ) =_____

 

void Func ( char str[100])

{

请计算sizeof( str ) =

}

 

void *p = malloc( 100 ); 请计算sizeof ( p ) =

 

char *str[]={“Hello”,”HI”, “x0”};

请计算:

sizeof(str)   =

sizeof(str[0]) =

 

11.在一个顺序存储结构里,LO表示第一个存储单元的地址,设每个存储单元的长度为m,则第n个存储单元的地址为____。

 

 

13.有关内存的思考题

 

Void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);

strcpy(str, “hello world”);

printf(str);

}

 

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

char *GetMemory(void)

{

char p[] = “hello world”;

return p;

}

void Test(void)

{

char *str = NULL;

str = GetMemory();

printf(str);

}

 

请问运行Test函数会有什么样的结果?

答:

Void GetMemory2(char **p, int num)

{

*p = (char *)malloc(num);

}

void Test(void)

{

char *str = NULL;

GetMemory(&str, 100);

strcpy(str, “hello”);

printf(str);

}

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

 

void Test(void)

{

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

strcpy(str, “hello”);

free(str);

if(str != NULL)

{

strcpy(str, “world”);

printf(str);

}

}

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

 

 

14.编写strcpy函数

已知strcpy函数的原型是

char *strcpy(char *strDest, const char *strSrc);

其中strDest是目的字符串,strSrc是源字符串。

 

(1)不调用C++/C的字符串库函数,请编写函数 strcpy

(2)strcpy能把strSrc的内容复制到strDest,为什么还要char * 类型的返回值?

 

 

喵呜刷题:让学习像火箭一样快速,快来微信扫码,体验免费刷题服务,开启你的学习加速器!

创作类型:
原创

本文链接:博大正方C语言参考试题

版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。
分享文章
share