C Quiz

Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.

1. What does a C compiler produce from your source code?

2. What kind of error is "undefined reference to `sqrt'" on Linux?

3. What does 7 / 2 evaluate to in C?

4. Which statement about the size of int is true?

5. What happens when a signed int overflows past INT_MAX?

6. Why is comparing 0.1 + 0.2 == 0.3 unreliable?

7. Which scanf specifier reads a double?

8. Why should you check the return value of scanf?

9. In if (x = 5), what happens?

10. What happens in a switch case without break?

11. Arguments to C functions are passed…

12. What is wrong with returning the address of a local variable?

13. What does static int count = 0; inside a function do?

14. How many bytes does char word[] = "cat"; occupy?

15. How do you correctly compare the text of two strings?

16. Why is snprintf preferred over sprintf and strcpy?

17. If int *p = &x;, what does *p = 7; do?

18. Inside void f(int a[]), what is sizeof a?

19. If double *p points to values[0], what does p + 2 point to?

20. What does const char *s promise?

21. What must you do after a successful malloc?

22. Why shouldn't you write p = realloc(p, n);?

23. Which tool finds buffer overflows and use-after-free bugs while your program runs?

24. What does the comparison function passed to qsort return?

25. With a pointer p to a struct, how do you access its score member?

26. How big is a union?

27. Which fopen mode erases an existing file?

28. In int main(int argc, char *argv[]), what is argv[0]?

29. Why should a function-like macro wrap its parameters in parentheses?

30. What does static mean on a function at file scope?