1. What does `\n` do in `printf`?
- Prints a backslash and n
- Ends the program
- Moves output to a new line
- Ends the program
Show answer
Answer: Moves output to a new line
`\n` is the newline escape sequence.
Lesson: Hello, World!
19 questions from the C Programming Fundamentals: Pointers, Memory and Files course, each with the correct answer and an explanation. Try to answer before you open the answer.
Answer: Moves output to a new line
`\n` is the newline escape sequence.
Lesson: Hello, World!
Answer: 3
Both operands are int, so the result is integer-divided to 3.
Lesson: Operators
Answer: do ... while
do ... while checks its condition after the body.
Lesson: Loops
Answer: It is destroyed
Local variables live on the stack and are freed once the function returns.
Lesson: Scope & Storage
Answer: The address of a function
You call the function through that address.
Lesson: Function Pointers & Callbacks
Answer: It compares pointer addresses, not contents
Arrays decay to pointers, so `==` compares addresses; use `strcmp` for content.
Lesson: string.h Functions
Answer: x and y are copies of the originals
Without pointers, the function only swaps its own local copies.
Lesson: Pointers & Functions
Answer: Shorthand for (*s).field
`->` dereferences the pointer and accesses the member in one step.
Lesson: Arrays of Structures
Answer: Set it to NULL
Setting it to NULL prevents accidental use-after-free bugs.
Lesson: Memory Leaks & Dangling Pointers
Answer: NULL
fopen returns NULL on failure -- always check before using the handle.
Lesson: Reading & Writing Files
Answer: ~ (NOT)
The bitwise NOT (~) inverts every bit of its operand.
Lesson: Bitwise Operators & Bit Flags
Answer: Compiles the source into an executable
-o names the output file.
Lesson: Debugging Basics
Answer: 3
Integer division truncates.
Lesson: Debugging Basics
Answer: It limits input to the buffer size
scanf %s has no bounds checking.
Lesson: Debugging Basics
Answer: Accesses the value it points to
* dereferences a pointer.
Lesson: Debugging Basics
Answer: Arguments are copied
Pass pointers to modify the originals.
Lesson: Debugging Basics
Answer: malloc
Pair every malloc with one free.
Lesson: Debugging Basics
Answer: Set it to NULL
It avoids dangling-pointer use.
Lesson: Debugging Basics
Answer: AddressSanitizer
Compile with -fsanitize=address.
Lesson: Debugging Basics