C语言基础知识考察

1、如下程序输出结果

#include <stdio.h>

void swap(int *a, int *b)

{

        int *p = NULL;

 

        p = a;

        a = b;

        b = p;

}

 

void main()

{

        int a = 5, b = 6;

 

        swap(&a, &b);

 

        printf("%d %d\n", a, b);

}

 

2、判断如下函数哪些能编译通过

void func1(void)

{

              int tmp = 0;

              const int *a = &tmp;

 

              *a = 1;

}

 

void func2(void)

{

              int tmp = 0;

              int* const a = &tmp;

 

              *a = 1;

}

 

void func3(void)

{

              int tmp = 0;

              int* const a = &tmp;

 

              a++;

}

 

void func4(void)

{

              int tmp = 0;

              const int const *a = &tmp;

 

              tmp++;

}

 

3、如下程序输出结果

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

void clear(int *a, int *b)

{

              *a = 0;

              *b = 0;

}

void swap(int *a, int *b)

{

              *a = *a + *b;

              *b = *a - *b;

              *a = *a - *b;

}

 

struct func_p_struct {

              int a;

              void (*func)(int *a, int *b);

              char * const c;

};

 

struct func_p_struct func_p_struct[] = {

              {1, swap, "swap"},

              {2, clear, "clear"},

};

 

void main()

{

              int index;

              int a = 5, b = 6;

 

              for (index = 0; index < sizeof(func_p_struct) / sizeof(func_p_struct[0]); index++) {

                            if (!strcmp(func_p_struct[index].c, "swap")) {

                                          func_p_struct[index].func(&a, &b);

                            }

              }

 

              printf("a = %d, b = %d\n", a, b);

}

 

 

4、32位机中如下程序输出结果

#include <stdio.h>

#include <string.h>

 

void main()

{

        char a[10] = "hello";

        char *b = "hello";

        char c[] = "hello";

 

        printf("%lu %lu %lu\n", sizeof(a), sizeof(b), sizeof(c));

 

        printf("%lu %lu %lu\n", strlen(a), strlen(b), strlen(c));

}

 

5、回答如下问题

(1)、 说明main函数参数及用法

(2)、.h文件能否定义全局变量

(3)、 .h文件如何避免被重复include

 

6、任选一题作答

(1)、 写一个小程序判断系统大小端

(2)、写一个小程序判断系统是32位还是64位

 

7、如下程序输出结果

#include<stdio.h>

 

#define IMI_TEST 0

 

void main()

{

#ifdef IMI_TEST

              printf("1\n");

#else

              printf("2\n");

#endif

      

#if IMI_TEST

              printf("1\n");

#else

              printf("2\n");

#endif   

}

 

8、写一个"标准"宏MIN ,这个宏输入两个参数并返回较小的一个

 

9、如下程序输出结果

 

#include<stdio.h>

 

struct s1 {

              int a;

              char c;

              int b;

};

 

struct s2 {

              int a:31;

              char c:1;

              int b:7;

};

 

void main()

{

              printf("%lu\n", sizeof(struct s1));

              printf("%lu\n", sizeof(struct s2));

}

 

10、如下程序输出结果

#include<stdio.h>

 

void func(int *a)

{

              static int s_cnt = 1;

 

              *a += ++s_cnt;

}

 

void main()

{

              int a = 0;

 

              func(&a);

              func(&a);

      

              printf("a = %d\n", a);

}

 

11、说明嵌入式系统中volatile的作用

 

12、说明如下变量的作用域、生存期、存储位置

#include<stdio.h>

 

int a;

static int b;

 

void main()

{

              int c;

      

              {

                            int d;

              }

}

 

a:

b:

c:

d:

 

13、说明进程与线程的概念

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值