Last Updated: January 3, 2026
30 quizzes
Which part of a function specifies the type of value it produces?
Where is it most appropriate to place function declarations for reuse across multiple .cpp files?
Which parameter type is best to pass a large std::string that should NOT be modified?
What is a key characteristic of pass-by-value parameters?
Which of these is a valid reason for using function overloading?
Where should you typically put default argument values for a function used across translation units?
Which statement about inline functions in modern C++ is most accurate?
In a well-formed recursive function, what must always be present?
Which lambda correctly captures all automatic variables by reference?
Which is a practical reason to pass a std::vector<T> by non-const reference to a function?
Declare a function that takes a const reference to std::string and returns its length
std::size_t lengthOf(const std::string& );Click an option to fill the blank:
Overload a function named logValue taking a double parameter
void logValue( value);Click an option to fill the blank:
Declare a lambda that captures all variables by value and takes an int x
auto func = [=]( x) { return x * 2; };Click an option to fill the blank:
What is the output of this code using pass-by-value vs pass-by-reference?
1#include <iostream>
2void incByValue(int x) { x++; }
3void incByRef(int& x) { x++; }
4int main() {
5 int n = 5;
6 incByValue(n);
7 incByRef(n);
8 std::cout << n << std::endl;
9 return 0;
10}What does this overloaded function call print?
1#include <iostream>
2void print(int x) { std::cout << "int" << std::endl; }
3void print(double x) { std::cout << "double" << std::endl; }
4int main() {
5 auto x = 3.0f;
6 print(x);
7 return 0;
8}What is the output of this recursive function?
1#include <iostream>
2int sumDown(int n) {
3 if (n <= 0) return 0;
4 return n + sumDown(n - 2);
5}
6int main() {
7 std::cout << sumDown(5) << std::endl;
8 return 0;
9}What does this lambda-based code output?
1#include <iostream>
2int main() {
3 int a = 1;
4 int b = 2;
5 auto f = [a, &b]() mutable {
6 a += 10;
7 b += 10;
8 std::cout << a << " " << b << "\n";
9 };
10 f();
11 std::cout << a << " " << b << std::endl;
12 return 0;
13}What will this inline function print when called?
1#include <iostream>
2inline int square(int x) { return x * x; }
3int main() {
4 int n = 3;
5 std::cout << square(++n) << " " << n << std::endl;
6 return 0;
7}Find the bug in this recursive factorial implementation
Click on the line(s) that contain the bug.
#include <iostream>int factorial(int n) { if (n == 0) { return 0; } return n * factorial(n - 1);}int main() { std::cout << factorial(3) << std::endl; return 0;}Find the bug related to default arguments and overloading
Click on the line(s) that contain the bug.
#include <iostream>void log(const std::string& msg, int level = 1) { std::cout << level << ": " << msg << std::endl;}void log(const std::string& msg, int level = 2); // declarationint main() { log("Hello"); return 0;}Click the line that causes unintended modification due to pass-by-reference
Click on the line to select.
#include <vector>void appendZero(std::vector<int>& v) { v.push_back(0);}int main() { std::vector<int> data{1,2,3}; appendZero(data); return 0;}Click the line where the lambda captures by value, preventing external modification
Click on the line to select.
#include <iostream>int main() { int counter = 0; auto f = [counter]() mutable { counter++; std::cout << counter << std::endl; }; f(); std::cout << counter << std::endl; return 0;}Complete the function that prints elements of a const std::vector<int> without copying it
#include <vector>#include <iostream>void printVec( std::vector<int> v) { for ( x : v) { std::cout << x << " "; } std::cout << std::endl;}Click an option to fill blank 1:
Complete the overloaded add functions with default arguments
int add(int a, int b = ) { return a + b;}double add(double a, double b = ) { return a + b;}int main() { std::cout << add(5) << " " << add(2.5) << std::endl;}Click an option to fill blank 1:
Complete the recursive function to compute power(base, exp) for non-negative exp
int power(int base, int exp) { if (exp == 0) return ; return base * ;}Click an option to fill blank 1:
Complete the lambda to sort a vector of ints in descending order using std::sort
#include <algorithm>#include <vector>#include <iostream>int main() { std::vector<int> v{1,4,2,3}; std::sort(v.begin(), v.end(), (int a, int b) { return ; }); for (int x : v) std::cout << x << " ";}Click an option to fill blank 1:
Match each parameter passing style with its typical use case
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each lambda capture form with its description
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Order the steps to design and use a new function in an existing C++ project
Drag and drop to reorder, or use the arrows.
Order the steps performed during a single recursive call to solve a problem
Drag and drop to reorder, or use the arrows.