C 测试题

1. Why (x=y)=z is illegal in C?

 

2. How to call C function in C++?

 

3. How to avoid multiple definition error in compiling time? in liking time?

 

4. What's generic pointer? What's generic function pointer?

 

5. What's memory leaking?

 

6. Explain the following:

(1) struct str *(*block())[8];

(2) double (*(*func)())[2][6];

 

7. Explain the following type names:

(1) int *[3]

(2) int (*)[3]

 

8. What's difference of type (signed) char and unsigned char?

 

9. What is the result in j?

short s = 0xA000;

unsigned long j;

j = (unsigned long) s;

 

10. How many keywords, how many precedences, how many operators, how many 
basic

type conversions in C?

 

11. How many name spaces in C?

 

12. Is the following code legal?

struct list { in x; struct list *list; } *list;

fun(struct list *list) {

list:

printf("%dn", list->x);

if ((list = list->list) != NULL)

goto list;

}

 

13. What's is qualified type?

 

14. Explain

int *const *const volatile *p;

 

15. Is the following code legal?

char c[] = "abc"def";

 

16. Why we need to avoid

int a;

a = (-9)/5;

 

17. Why we need to avoid the code such as:

y[i] = x[i++];

 

18. What's difference between sizeof and strlen()?

 

19. How is the unsigned number 0xaabbccdd layed out in the little endian 
computer(such as PC)?

In the big endian computer?

 

20. In the code

float *p, f[128];

p = f;

p = p + 120;

p is always pointing to f[120] independent on the machine?

 

21. In the code

int a;

a = 4 > 3;

how many is a?

 

22. In the code

while(-1) {

fun();

}

Will fun() run forever?

 

23. Is the following code legal?

struct { int x, y; } *p;

struct { int x, y; } *q;

main() { p = q; }

 

24. Is 123.4.5 a valid preprocessing number?

 

25. What's the problem with the following macro definition:

#define twice(x) (2*x)

 

26. Is the following code legal?

switch (n%4) {

while (n>0) {

case 0: *x++ = *y++; n--;

case 3: *x++ = *y++; n--;

case 2: *x++ = *y++; n--;

case 1: *x++ = *y++; n--;

}

}

 

27. In the following, which one is legal?

(1) static int x;

extern int x;

(2) extern int x;

static int x;

 

28. What's the layout for 2-D arrays in the memory?

 

29. Is the following code legal?

int b[100], p;

for (p = b; p < &b[100]; p++) *p = 0;

 

30. What's difference when reading a file using binary-mode or text-mode?

 

 

The following questions are related to compiler design:

 

31. Returning the address of a local variable is a common programming error.

Why the C compiler cannot catch such errors at compile-time?

 

32. In the following code:

int g(int, int);

int f(n) int n; {

int i = 0, j;

if (n == 1) i = 2;

while (n > 0) {

j = i + 1;

n = g(n, i);

}

return j;

}

Why do we say "whether the while loop terminates is recursively undecidable"?

 

33. What are text area, data area and bss area?

 

 

The following questions are related to the new C 1999 Standard

 

34. Explain the new keyword "restrict".

 

登录后才可评论.