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?
C is compiled ahead of time into a native executable (lessons 01 and 04).
2. What kind of error is "undefined reference to `sqrt'" on Linux?
The code compiled, but the linker couldn't find the function's definition (lessons 04 and 25).
3. What does 7 / 2 evaluate to in C?
Integer division discards the fractional part (lesson 07).
4. Which statement about the size of int is true?
Use stdint.h types when you need an exact size (lessons 07–08).
5. What happens when a signed int overflows past INT_MAX?
Unsigned arithmetic wraps; signed overflow is undefined (lessons 08 and 54).
6. Why is comparing 0.1 + 0.2 == 0.3 unreliable?
Compare with a tolerance instead (lesson 09).
7. Which scanf specifier reads a double?
%f is for float in scanf (although printf uses %f for both) (lesson 15).
8. Why should you check the return value of scanf?
(lesson 15)
9. In if (x = 5), what happens?
Use == to compare; compilers warn about this (lesson 04).
10. What happens in a switch case without break?
(lesson 17)
11. Arguments to C functions are passed…
To let a function change a variable, pass its address (lessons 22 and 31).
12. What is wrong with returning the address of a local variable?
(lessons 23 and 34)
13. What does static int count = 0; inside a function do?
(lesson 23)
14. How many bytes does char word[] = "cat"; occupy?
Three letters plus the '\0' terminator (lesson 28).
15. How do you correctly compare the text of two strings?
== compares addresses (lesson 29).
16. Why is snprintf preferred over sprintf and strcpy?
(lessons 11 and 29)
17. If int *p = &x;, what does *p = 7; do?
* dereferences the pointer (lesson 31).
18. Inside void f(int a[]), what is sizeof a?
Arrays decay to pointers when passed; pass the length separately (lesson 32).
19. If double *p points to values[0], what does p + 2 point to?
Pointer arithmetic moves by whole elements (lesson 33).
20. What does const char *s promise?
char *const s would be a pointer that can't move (lesson 35).
21. What must you do after a successful malloc?
Otherwise the memory leaks (lesson 36).
22. Why shouldn't you write p = realloc(p, n);?
Assign to a temporary first (lesson 37).
23. Which tool finds buffer overflows and use-after-free bugs while your program runs?
(lesson 38)
24. What does the comparison function passed to qsort return?
(lessons 39 and 46)
25. With a pointer p to a struct, how do you access its score member?
p->score means (*p).score (lesson 41).
26. How big is a union?
All members share the same memory (lesson 42).
27. Which fopen mode erases an existing file?
(lesson 47)
28. In int main(int argc, char *argv[]), what is argv[0]?
(lesson 49)
29. Why should a function-like macro wrap its parameters in parentheses?
SQUARE(2 + 3) without parentheses gives 11 (lesson 51).
30. What does static mean on a function at file scope?
Internal linkage (lessons 23 and 52).