请在40分钟内完成以下20道C语言基础题。在没有任何提示的情况下,如果能得满分,那么你可以扔掉本书了,你的水平已经大大超过了作者;如果能的80分以上,说明你的C语言基础还不错,学习本书可能会比较轻松;如果得分在50分以下,也不要气馁,努力学习就行了;如果不小心得了10分以下,你就得给自己悄悄警钟了;如果不幸得了0分,那实在是不应该,因为毕竟很多题是很简单的。
 
C语言基础题(每题5分)。
1. 下面的代码输出时什么?为什么?
 C++ Code 

1

2

3

4

5

6

 
void foo(
void)

{

    
unsigned 
int a = 
;

    
int b = -
;

    (a + b > 
) ? puts(
">6") : puts(
"<=6");

}


2. 下面的代码有什么问题?为什么?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

 
void foo(
void)

{

    
char string[
], str1[
];

    
int  i;

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

    {

        str1[i] = 
'a';

    }

strcpy(string, str1);

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

}


3. 下面的代码,i和j的值分别是什么?为什么?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

 
static 
int j;


int k = 
;

void fun1(
void)

{

    
static 
int i = 
;

    i++;

}


void fun2(
void)

{

    j = 
;

    j++;

}

int main(
void)

{

    
for(
int k = 
; k < 
; ++k)

    {

        fun1();

        fun2();

    }

return 
;

}


4. 下面代码里,假设在32位系统下,个sizeof计算的结果分别是多少?
int *p = NULL;

sizeof(p) = 
sizeof(*p) = 

int a[100];

sizeof(a) = 
sizeof(a[100]) = 
sizeof(&a) = 
sizeof(&a[0]) = 

int b[100];
void fun(int b[100])
{
    sizeof(b) = 
}

5. 下面代码的结果是多少?为什么?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

 
#include 
"stdio.h"


#include 
"string.h"

int main(
void)

{

    
signed 
char a[
];

    
int i;

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

    {

        a[i] = -i - 
;

    }

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

    
return 
;

}


6. 下面的代码里,哪些内容可被改写,哪些不可被改写?
(1)const int *p;
(2)int const *p;
(3)int * const p;
(4)const int *const p;

7.下面的两端代码又什么区别?什么时候需要使用代码(2)?
代码(1):
int i = 10;
int j = i;
int k = i;

代码(2):

volatile int i = 10;
int j = i;
int k = i;

8. 在32位的x86系统下,输出的值为多少?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

 
#include 
"stdio.h"

int main(
void)

{

   
int a[
] = {
,
,
,
,
};

   
int *ptr1 = (
int*)(&a + 
);

   
int *ptr2 = (
int*)((
int)a + 
);

printf(
"%x, %x\n", ptr1[-
],*ptr2);

return 
;

}


9. 0x01 <<2+3的值为多少?为什么?

10. 定义一个函数宏,求x的平方

11. 下面的两段代码有什么区别?
代码(1):
struct TestStruct1
{
    char c1;
    short s;
    char c2;
    int i;
};
代码(2):
struct TestStruct2
{
    char c1;
    char c2;
    short s;
    int i;
};

12. 写代码向内存0x12ff7c地址存入一个整形术0x100.

13. 下面代码的值是多少?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

 
#include 
"stdio.h"

int main(
void)

{

   
int a[
] = {
,
,
,
,
};

   
int *ptr = (
int*)(&a + 
);

printf(
"%d, %d\n", *(a + 
),*(ptr - 
));

return 
;

}


14. 假设p的值为0x10000,如下表达式的值分别为多少?
struct Test
{
    int     Num;

    char    * pcName;

    short    dDate;

    char    cha[2];

    short    sBa[4];

}* p;

p + 0x1 = 0x    ?
(unsigned long)p + 0x1 = 0x    ?
(unsigned int *)p + 0x1 = 0x    ?

15. 下面代码输出的结果是多少?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

 
#include 
"stdio.h"

int main(
void)

{

   
int a[
][
] = {(
,
),(
,
),(
,
)};

   
int *p;

   p = a[
];

   printf(
"%d\n", p[
]);

return 
;

}


16. 下面的代码有什么问题?为什么?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

 
void fun(
char a[
])

{

    
char c = a[
];

}

int main(
void)

{

    
char b[
] = 
"abcdefg";

    fun(b[
]);

    
return 
;

}


17. 下面的代码有什么问题?为什么?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

 
#include 
"stdlib.h"


#include 
"string.h"


struct student

{

    
char *name;

    
int score;

} stu, *pstu;


int main(
void)

{

    pstu = (
struct student *)malloc(
sizeof(
struct student));

    strcpy(pstu->name, 
"Jimy");

    pstu->score = 
;

    free(pstu);

    
return 
;

}


18. 下面的代码输出结果是多少?
 C++ Code 

1

2

3

4

5

6

7

8

9

10

11

12

13

 
#include 
"stdio.h"


void fun(
int i)

{

   
if(i > 
)

      fun(i/
);

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

}


int main(
void)

{

   fun(
);

   
return 
;

}


19. 下面的代码有什么问题?为什么?
char c;
c = getchar();
if(EOF == c)
{
    ...

}

20. 请写一个C函数,若当前系统是Big_endian的,则返回0;若是Little_endian的,则返回1。

PS:答案回复可见。
O(∩_∩)O~

《C语言深度解剖》面试题整理的更多相关文章

  1. 高质量程序设计指南C/C++语言——C++/C程序设计入门

    1.在C++/C中,全局变量(extern或static)存放在程序的静态数据区中,在程序进入main()之前创建,在main()结束之后销毁,因此在我们的代码中根本没有机会初始化它们,于是语言及其实 ...

  2. 高质量程序设计指南C/C++语言——C++/C程序设计入门(4)

    *switch结构的break语句只是一个“jmp”指令,其作用就是跳到switch结构的结尾处 *标准C++/C语言提供3种循环:do/while.while和for,它们都在条件表达式为TRUE( ...

  3. 指针,数组,字符串的区别(高质量程序设计指南C++/C语言第7章)

    指针: 指针是变量,和平时的那些变量没有本质的差异,不同的只是它的值和类型,.,即解释方式 二进制层面:指针的值是内存单元的地址,而变量是引用内存单元值的别名 语言层面:指针的值就是变量的地址. 对象 ...

  4. 高质量程序设计指南C/C++语言——malloc/free使用要点

  5. 高质量程序设计指南C/C++语言——有了malloc/free为什么还要new/delete?

  6. 高质量程序设计指南C/C++语言——内存管理

    • free()和delete只是把指针所指的内容给释放掉,并没有把指针本身删掉.指针被free()或delete以后其地址仍然不变(不等于NULL),只是该地址对应的内存是垃圾——p成了野指针.如果 ...

  7. 高质量程序设计指南C/C++语言——C++/C常量(2)

  8. 高质量程序设计指南C/C++语言——C++/C程序设计入门(2)

    *标准C规定,编译器只取前31个字符作为有效的标识符,而标准C++则取前255个字符作为有效的标识符. *把具有特殊含义的字符输出到终端上,尤其是当它们出现在普通字符串或格式控制字符串中时,一般来说有 ...

  9. 高质量程序设计指南C/C++语言——C++/C编译预处理

    C++/C的编译预处理器对预编译伪指令进行处理后生成中间文件作为编译器的输入,因此所有的预编译伪指令都不会进入编译阶段.预编译伪指令一般都以#打头,且其前面只能出现空白字符.预编译伪指令不是C++/C ...

  10. 高质量程序设计指南C/C++语言——C++/C常量

随机推荐

  1. Map 的遍历

    一.Map的遍历 在后面java的开发过程中会遇到Map类的使用,然而map的遍历是一大问题. Map遍历用两种比较交代的方法: package edu.map; import java.util.H ...

  2. Eclipse使用笔记

    eclipse内容辅助键 alt+ /用法: Alt+/ 提示作用 帮助补齐一些东西,还可以帮助你起名字, main+alt+/,syso+alt+/ alt+shift+s给出一些快捷操作,比如fo ...

  3. Quiz 6b Question 8————An Introduction to Interactive Programming in Python

     Question 8 We can use loops to simulate natural processes over time. Write a program that calcula ...

  4. WEB ICON 的探讨

    一般考虑到webicon 就是cssSprite和自定义font:本文基于下述而总结和进行分析,如有笔误有望指出,谢谢 在线教程:用字体在网页中画ICON图标 http://www.imooc.com ...

  5. Spring @Resource注解

    @Resource注解   @Resource 注解被用来激活一个命名资源(named resource)的依赖注入,在JavaEE应用程序中,该注解被典型地转换为绑定于JNDI context中的一 ...

  6. Nginx 之五: Nginx服务器的负载均衡、缓存与动静分离功能

    一.负载均衡: 通过反向代理客户端的请求到一个服务器群组,通过某种算法,将客户端的请求按照自定义的有规律的一种调度调度给后端服务器. Nginx的负载均衡使用upstream定义服务器组,后面跟着组名 ...

  7. box-shadow 被其他div遮住 shadow was hidden/covered by another div

    使用z-index 来处理 (z-index必须在使用了position的情况下才有效) 参考http://stackoverflow.com/questions/5505118/css-box-sh ...

  8. (3)选择元素——(2)文档对象模型(The Document Object Model)

    One of the most powerful aspects of jQuery is its ability to make selecting elements in the DOM easy ...

  9. Android zip文件压缩解压缩

    DirTraversal.java <P style="TEXT-ALIGN: left; PADDING-BOTTOM: 0px; WIDOWS: 2; TEXT-TRANSFORM ...

  10. CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD

    题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...