c语言常见笔试题总结
【1 使用宏】
1.1
#ifdef NDEBUG
#defineTRACE(S) S
#else
#defineTRACE(S) printf("%s;\n", #S); S
#endif
问:以上TRACE()宏的作用是什么?
1.2 #error的作用?
1.3 定义一个宏,求出给定数组中的元素的个数
#define NELEMENTS(array) ??
1.4 定义一个宏,求出给定结构中给定成员的偏移量
#define OFFSET(structure, member) ??
【2 数据声明和定义】
给定以下类型的变量a的定义式:
a) An integer
b) A pointer to an integer
c) A pointer to a pointer to an integer
d) An array of 10 integers
e) An array of 10 pointers to integers
f) A pointer to an array of 10 integers
g) A pointer to a
function thattakes an integer as an argument and returns an integer
h) An array of ten pointers to
functions that take an integer argument and return aninteger
【3 复杂类型(1)】
有如下表达式:
char(*(*x())[])();
请用文字描述x是什么。
【4 复杂类型(2)】
jmp_buf的定义:
typedefstruct _jmp_buf
{
REG_SET reg;
int extra[3];
} jmp_buf[1];
setjmp函数的原型:
extern intsetjmp (jmp_buf __env);
问:调用setjmp时传递__env的内容,还是传递指针?
【5 头文件】
问:为什么标准头文件都有类似以下的结构?
#ifndef__INCvxWorksh
#define__INCvxWorksh
#ifdef__cplusplus
extern"C" {
#endif
/*...*/
#ifdef__cplusplus
}
#endif
#endif /*__INCvxWorksh */
【6 static关键字】
请说出static关键字的3种用处:
(1)用于全局变量;
(2)用于局部变量;
(3)用于函数。
/* file.c */
static int a;
int b;
static int fn()
{
static int x;
int y;
}
【7 const关键字】
7.1 const关键字的意义是什么?
7.2 解释以下的变量定义:
const int a1;
int const a2;
const int *a3;
int * const a4;
int const * const a5;
【8 volatile关键字】
8.1 volatile意义?例如
volatile int *p;
8.2 volatile能和const一起使用吗?例如
volatile const int *p;
【9 sizeof()】
有以下定义:
char *pmsg ="A";
char msg[] ="A";
char ch = 'A';
问:
sizeof(pmsg) = ?
sizeof(msg) = ?
sizeof(“A”) = ?
sizeof(ch) = ?
sizeof(‘A’) = ? (在C++中等于多少?)
void f(char param[100])
{
// sizeof(param) = ?
}
【10 字符串】
有以下代码
char *pmsg ="hello, world!";
strcpy(pmsg,"hi, there.");
试评论该代码。
【11 混合运算】
有以下代码:
void foo()
{
unsigned int a = 6;
int b = -20;
(a+b 6) ? puts(" 6") : puts("
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。