Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

📝 Knowledge Test

/
Knowledge Test Score Board
· 0%

Work through the questions below — your score updates as you go.

Keep going · grade bands mapped to DCU's honours scale

target18:45

Only your first attempt at each question counts toward this score. Reload the page to reset.

This section contains 25 interactive knowledge checks designed to test your understanding of the materials covered in Chapter 3. The questions span C++ history, fundamental types, pointers, control flow, string manipulation, bitwise operations, and exception handling.

Please remember that many of the quizzes have multiple correct answers, and you must select all applicable options to succeed. I have carefully balanced the lengths of the answers, so take your time to evaluate each option thoroughly.

Good luck!

Derek.


Q1
Quiz
Select 0/2

Which of the following statements accurately describe the evolution and standardisation of the C++ programming language?

C++ was developed by Bjarne Stroustrup as 'C with Classes' to integrate object-oriented features with the low-level memory efficiency of C.
The ISO committee enforces strict backward compatibility, meaning code written for older compilers is guaranteed to compile flawlessly on modern ones.
Modern standardisation efforts, such as C++11, C++14, and C++23, continuously update the language to introduce safer and more efficient features.
The C++ language is purely object-oriented, meaning that procedural programming styles (like standard C functions) are strictly prohibited.
Q2
Code Cloze
C++

Complete the Modern C++ Constants and Types

Drag snippets from the pool into the blanks so the program produces the output shown, then click Submit.

1#include <·····>
2
3// Platform-independent 8-bit unsigned integer
4····· hardware_register = 0xFF;
5
6// Inform the compiler this value might change externally
7····· int sensor_reading = 0;

Available Snippets

const
stdint
static
cstdint
iostream
unsigned char
uint8_t
volatile
Q3
Code Gap Check
C++

Compile-time Constants

1// Ensure a constant is evaluated at compile time
2// select an option below
volatile int MAX_BUFFER_SIZE = 1024;
constexpr int MAX_BUFFER_SIZE = 1024;
const int MAX_BUFFER_SIZE = 1024;
static int MAX_BUFFER_SIZE = 1024;
Q4
Quiz
Select 0/3

When configuring a C++ compiler like GCC for an embedded project, how do the optimisation flags (e.g., -O0, -O3, -Os) affect the resulting code?

The '-Ofast' flag strictly enforces all ANSI/ISO C++ standards to guarantee mathematical precision, automatically slowing down execution.
The '-O3' flag aggressively applies inlining and loop unrolling to maximize execution speed, though it may increase the final compiled binary size.
The '-O0' flag entirely disables compiler optimisations, ensuring the generated machine code exactly matches the source code for straightforward debugging.
The '-Os' flag is specifically designed to reduce the physical size of the compiled machine code, making it ideal for flash-constrained microcontrollers.
Q5
Code Output
C++

Predict the output of Type Conversion and Division

Read the code below, then choose the terminal output it produces and click Submit.

1#include <iostream>
2
3int main() {
4 int x = 7;
5 int y = 2;
6 float z = x / y;
7
8 std::cout << z << "\n";
9 std::cout << static_cast<float>(x) / y << "\n";
10 return 0;
11}
stdout
3.5
3.5
stdout
3
3
stdout
3
3.5
stdout
3.5
3
Q6
Concept Match

Match the Modern C++ Construct to its Benefit

Drag each definition into its matching concept slot, then click Submit. Tap × to return a placed card to the pool.

enum class
drag a definition here…
using alias
drag a definition here…
std::byte
drag a definition here…
[[nodiscard]]
drag a definition here…

Definition Pool

A non-arithmetic type representing raw memory bits, preventing accidental numeric calculations.
A compiler attribute that issues a warning if the programmer ignores a function's returned value.
A modern, highly readable alternative to typedef that supports template aliasing (e.g., Name = Value).
A scoped enumeration that prevents name collisions and provides strict type safety.
Q7
Quiz
Select 0/3

Which of the following statements about C++ Pointers and Memory are correct?

A void* pointer can safely be dereferenced directly to access data, as the compiler automatically determines the correct underlying data type.
The 'nullptr' keyword (introduced in C++11) represents a type-safe null pointer and should always be preferred over the legacy 'NULL' macro.
The address-of operator (&) returns the specific physical or virtual memory location where a given variable is stored.
The dereference operator (*) retrieves the actual data value stored at the memory address currently held by the pointer.
Q8
Code Gap Check
C++

Pointer Member Access

1struct Sensor {
2 void initialize() {}
3};
4
5int main() {
6 Sensor* s = new Sensor();
7 // Access the initialize method via the pointer
8 // select an option below
9 delete s;
10 return 0;
11}
s->initialize();
s.&initialize();
s.*initialize();
s.initialize();
Q9
Code Cloze
C++

Complete the Pointer Arithmetic Logic

Drag snippets from the pool into the blanks so the program produces the output shown, then click Submit.

1int data[3] = {10, 20, 30};
2int *ptr = &data[0];
3
4// Increment the pointer to point to the next element
5ptr·····;
6
7// Dereference the pointer to retrieve the current value
8int current_value = ·····ptr;
9
10// Safely assign a null state when finished
11ptr = ·····;

Available Snippets

*
--
++
&
NULL
nullptr
void
Q10
Code Output
C++

Predict the output: Pointer Precedence

Read the code below, then choose the terminal output it produces and click Submit.

1#include <iostream>
2
3int main() {
4 int arr[] = {5, 10, 15};
5 int *p = arr;
6
7 std::cout << *p++ << " ";
8 std::cout << (*p)++ << " ";
9 std::cout << *p;
10
11 return 0;
12}
stdout
5 10 15
stdout
5 10 11
stdout
6 11 11
stdout
5 11 15
Q11
Quiz
Select 0/2

Why is 'Pass by Const Reference' (e.g., void process(const std::string& data)) considered a modern C++ best practice for large objects?

It passes a lightweight reference rather than creating a full memory copy of the object, significantly improving runtime efficiency.
The 'const' qualifier strictly guarantees that the function cannot accidentally alter the original data, ensuring program safety.
It automatically converts the object into a C-style char array before passing it into the function block.
It allows the function to freely modify the original object in memory, bypassing any encapsulation restrictions applied by the class.
Q12
Concept Match

Match the Memory or Scope Concept

Drag each definition into its matching concept slot, then click Submit. Tap × to return a placed card to the pool.

Pass by Value
drag a definition here…
Pass by Reference
drag a definition here…
Variable Scope
drag a definition here…
Dangling Pointer
drag a definition here…

Definition Pool

An alias to the original variable is passed, allowing the function to modify the source data directly.
A pointer that references a memory location that has already been deallocated or destroyed.
A complete copy of the variable is sent to the function; changes do not affect the original data.
The designated area within a program (often defined by curly braces {}) where a variable is active and accessible.

Part 3: Strings, Namespaces, and Control Flow

Section titled “Part 3: Strings, Namespaces, and Control Flow”
Q13
Quiz
Select 0/3

Which of the following describes the differences between C-style strings (<cstring>) and modern C++ strings (<string>)?

The C standard library function 'strcmp()' is used to intuitively combine two C-style strings together without memory overflow risks.
C-style strings are fundamental arrays of characters that must be manually terminated with a special null character ('\0').
The modern 'std::string_view' provides a highly efficient, read-only view of a string without triggering costly memory allocations.
Modern std::string objects automatically manage their own underlying memory and can be safely concatenated using the standard '+' operator.
Q14
Code Output
C++

Predict the output: Loops and Break/Continue

Read the code below, then choose the terminal output it produces and click Submit.

1#include <iostream>
2
3int main() {
4 for(int i = 1; i <= 5; ++i) {
5 if (i == 3) { continue; }
6 if (i == 5) { break; }
7 std::cout << i;
8 }
9 return 0;
10}
stdout
12345
stdout
1245
stdout
124
stdout
12
Q15
Code Gap Check
C++

Efficient String Handling

1#include <iostream>
2#include <string_view>
3
4// Pass a read-only view of a string without copying
5// select an option below
6 std::cout << "Status: " << message << std::endl;
7}
void print_status(const char* message)
void print_status(std::string message)
void print_status(std::string_view message)
void print_status(std::string& message)
Q16
Code Cloze
C++

Modern Range-Based For Loop

Drag snippets from the pool into the blanks so the program produces the output shown, then click Submit.

1#include <iostream>
2#include <vector>
3
4int main() {
5 std::vector<int> numbers = {10, 20, 30};
6
7 // Safely iterate through the vector without copying elements
8 for (····· auto····· num : numbers) {
9 std::cout << num << " ";
10 }
11 return 0;
12}

Available Snippets

std::
const
*
void
&
static
Q17
Quiz
Select 0/2

Based on the 'Robot Arena' Virtual Lab, why is introducing a mutable variable (like 'ammo') significantly different from pure control flow (like a 'while' loop)?

It forces the programmer to read the variable's current value inside a conditional (e.g., if ammo == 0) to make real-time operational decisions.
It eliminates the need for any block scope braces in the source code, as the variable handles all logic branching automatically.
Mutable variables automatically pause the execution of the CPU, giving the hardware time to synchronise with external moving targets.
A mutable variable introduces persistent state, meaning the program must actively track and update a value that changes dynamically over time.
Q18
Concept Match

Match the String Function to its Behavior

Drag each definition into its matching concept slot, then click Submit. Tap × to return a placed card to the pool.

strlen()
drag a definition here…
strcat()
drag a definition here…
std::getline()
drag a definition here…
std::string::at()
drag a definition here…

Definition Pool

A C-style function that appends one char array to another, which can cause buffer overflows if not careful.
A C++ function used with cin to read an entire line of text, including spaces and tabs.
Accesses a character in a C++ string safely by performing runtime bounds checking.
A C-style function that calculates string length by counting bytes until it hits the null terminator.

Part 4: Bitwise Operations, Precedence, and Exceptions

Section titled “Part 4: Bitwise Operations, Precedence, and Exceptions”
Q19
Quiz
Select 0/2

Why are bitwise operations considered essential for low-level embedded edge programming?

They automatically translate human-readable string commands into secure, encrypted binary machine code payloads.
They allow developers to set, clear, or toggle specific individual bits within a hardware configuration register without disturbing adjacent bits.
They allow multiple floating-point values to be securely compressed into a single 8-bit character array.
They provide an extremely fast, computationally efficient method to perform multiplication and division by powers of two using shift operators.
Q20
Code Output
C++

Predict the output: Bitwise Shifting

Read the code below, then choose the terminal output it produces and click Submit.

1#include <iostream>
2#include <cstdint>
3
4int main() {
5 uint8_t a = 5; // Binary: 00000101
6 uint8_t b = a << 2;
7 uint8_t c = b >> 1;
8
9 std::cout << (int)b << " " << (int)c;
10 return 0;
11}
stdout
10 5
stdout
20 10
stdout
7 6
stdout
20 5
Q21
Code Gap Check
C++

Toggling Bit States

1uint8_t flags = 0b00000001;
2// Use bitwise XOR to toggle the state of the first bit
3// select an option below
flags ^= 0b00000001;
flags &= 0b00000001;
flags |= 0b00000001;
flags ~= 0b00000001;
Q22
Code Cloze
C++

Structure a C++ Exception Handler

Drag snippets from the pool into the blanks so the program produces the output shown, then click Submit.

1#include <iostream>
2#include <vector>
3#include <stdexcept>
4
5int main() {
6 std::vector<int> data = {1, 2, 3};
7 ····· {
8 int value = data.at(10); // Will throw out_of_range
9 }
10 ····· (const std::·····& e) {
11 std::cerr << "Error: " << e.·····() << "\n";
12 }
13 return 0;
14}

Available Snippets

throw
fail
exception
catch
error
out_of_range
message
try
what
Q23
Concept Match

Match the Operator or Exception Concept

Drag each definition into its matching concept slot, then click Submit. Tap × to return a placed card to the pool.

Bitwise XOR (^)
drag a definition here…
Bitwise NOT (~)
drag a definition here…
Stack Unwinding
drag a definition here…
noexcept
drag a definition here…

Definition Pool

Compares two numbers bit-by-bit; the resulting bit is 1 only if the corresponding bits are different.
A keyword promising the compiler that a specific function will absolutely never throw an exception.
A unary operator that inverts all the bits of a number, turning 1s to 0s and vice versa.
The process where the runtime system safely destroys local objects as it searches upward for an exception handler.
Q24
Code Gap Check
C++

Catching Exceptions by Reference

1try {
2 risky_operation();
3}
4// Catch the standard exception by constant reference
5// select an option below
6 std::cerr << "Caught standard exception";
7}
catch (...)
catch (const std::exception& e)
catch (exception& e)
catch (std::exception e)
Q25
Quiz
Select 0/2

Regarding operator precedence in C++, why is it heavily recommended to wrap bitwise operations in parentheses when evaluating conditions?

Because the compiler will immediately crash and refuse to compile any bitwise logic that lacks enclosing parentheses.
Because relying on obscure precedence rules makes code incredibly difficult for other developers to read and maintain.
Because bitwise operators (like &, |) often have a lower precedence than equality operators (like ==), leading to unintended evaluation order.
Because parentheses physically instruct the CPU's arithmetic logic unit (ALU) to cache the values in faster SRAM.

Congratulations on completing the Chapter 3 Knowledge Test! Review any questions you missed to ensure a solid foundation in the “C of C++” before moving on to the advanced Object-Oriented implementations in Chapter 5.