Learn Quiz

C / C++ Quiz

Test your systems programming knowledge. — 8 questions

Question 1 of 8 Score: 0

About the C / C++ Quiz

Test your systems programming knowledge. This quiz has 8 multiple-choice questions. Each question has one correct answer, and you see an explanation straight after you answer, so you learn from every question — including the ones you get wrong. There is no time limit and nothing to sign up for; your answers are not stored.

The questions follow the material in the C / C++ Essentials guide and the C / C++ cheatsheet. Read them first if you want to prepare, or take the quiz cold to find the gaps in what you know.

Questions in this quiz

Preview the questions below. Each answer and its explanation are hidden until you choose to reveal them, so you can still take the quiz above without spoilers.

1. What does a pointer store?

  1. A copy of a value
  2. The memory address of a variable
  3. The size of a variable
  4. A reference to an object
Show answer

Answer: B. The memory address of a variable
A pointer holds the memory address of another variable. Use & to take an address and * to dereference.

2. Which operator dereferences a pointer?

  1. &
  2. *
  3. ->
  4. ::
Show answer

Answer: B. *
* dereferences: *ptr gives the value at the stored address. & takes the address of a variable. -> dereferences and accesses a member.

3. What does malloc return if allocation fails?

  1. -1
  2. 0
  3. NULL
  4. It throws an exception
Show answer

Answer: C. NULL
malloc returns NULL on failure. C does not use exceptions — always check the return value before using the pointer.

4. What is a C++ reference?

  1. A pointer that can be null
  2. An alias for an existing variable
  3. A heap-allocated value
  4. A read-only copy of a value
Show answer

Answer: B. An alias for an existing variable
A reference is an alias: int& ref = x means ref and x share the same memory. References cannot be null or re-seated.

5. Which header is required for cout in C++?

  1. <stdio.h>
  2. <iostream>
  3. <cstdlib>
  4. <string.h>
Show answer

Answer: B. <iostream>
<iostream> provides std::cout and std::cin. <stdio.h> provides the C-style printf/scanf.

6. What does delete[] do?

  1. Deletes the first element of an array
  2. Frees memory allocated with new[]
  3. Clears array contents but keeps memory
  4. Removes an element from a vector
Show answer

Answer: B. Frees memory allocated with new[]
delete[] must match new[]. Using plain delete on an array is undefined behavior.

7. What is the difference between pass-by-pointer and pass-by-reference in C++?

  1. No difference
  2. References cannot be null and need no dereference syntax
  3. Pointers are always faster
  4. References cannot be used with heap memory
Show answer

Answer: B. References cannot be null and need no dereference syntax
References are safer: they cannot be null, cannot be re-seated, and are accessed without * dereference syntax.

8. What is sizeof(int) on most modern systems?

  1. 2 bytes
  2. 4 bytes
  3. 8 bytes
  4. Depends on the value stored
Show answer

Answer: B. 4 bytes
int is 4 bytes on both 32-bit and 64-bit systems (per common ABIs). Use int64_t / long long for guaranteed 64-bit.

How to use this quiz

  • Answer every question before reading the explanations below — retrieving an answer from memory is what makes it stick.
  • Note the questions you missed and revisit the matching section of the guide or cheatsheet.
  • Retake the quiz a day or two later. Spaced repetition is one of the most reliable ways to remember technical details.

Related