🌍 C++ Programming · flashcards

C++ Programming Functions Flashcards

50 question-and-answer cards covering Functions as it is examined in C++ Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
7Syllabus topics
~200Chars per answer
FreePrice

24 sample cards from the Functions deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is the rule about the position of default arguments in a parameter list?

    Default arguments must be the trailing (rightmost) parameters. Once a parameter has a default, all parameters to its right must also have defaults.

  2. Where should default arguments be specified when a function is both declared and defined separately?

    They should be given in the declaration (typically in the header), not repeated in the definition. Specifying the same default in both places is an error; the caller only sees the declaration.

  3. How can default arguments sometimes replace function overloading?

    A single function with default arguments can serve callers who pass different numbers of arguments, e.g. int box(int l, int w = 1, int h = 1); handles box(l), box(l,w), and box(l,w,h) without writing three overloads.

  4. What is a potential conflict between default arguments and function overloading?

    They can create ambiguity: if an overload can be called with fewer arguments due to defaults, and another overload matches that same call, the compiler cannot decide, producing an ambiguous-call error.

  5. Define recursion in the context of functions.

    Recursion is a technique where a function calls itself, directly or indirectly, to solve a problem by breaking it into smaller subproblems of the same form.

  6. What two essential components must every correct recursive function have?

    A base case (terminating condition that stops the recursion) and a recursive case (the function calling itself on a smaller/simpler input that progresses toward the base case).

  7. What happens if a recursive function has no reachable base case?

    It recurses infinitely, consuming stack frames until the call stack is exhausted, causing a stack overflow (and program crash).

  8. Write a recursive definition of factorial and its base case.

    $$n! = \begin{cases} 1 & n = 0 \\ n \times (n-1)! & n > 0 \end{cases}$$ Base case: $0! = 1$; recursive case multiplies $n$ by the factorial of $n-1$.

  9. What is the time complexity of the naive recursive Fibonacci that computes $F(n)=F(n-1)+F(n-2)$?

    Exponential time, $O(\varphi^{n})$ where $\varphi = \frac{1+\sqrt{5}}{2}$ (commonly stated as $O(2^{n})$), because it recomputes the same subproblems repeatedly. Space is $O(n)$ for the call stack.

  10. What is the difference between direct and indirect recursion?

    Direct recursion: a function calls itself directly (f calls f). Indirect (mutual) recursion: a function calls another function that eventually calls the first back (f calls g, and g calls f).

  11. What is tail recursion?

    A recursive call that is the very last operation performed in the function, with nothing left to do after it returns. Compilers can optimize it into a loop (tail-call optimization), using constant stack space.

  12. Compare recursion and iteration in terms of memory usage.

    Iteration uses a fixed amount of stack space (typically one frame). Recursion allocates a new stack frame for each call, so it uses O(depth) stack memory and risks stack overflow for deep recursion.

  13. What is the recurrence relation form used to analyze many recursive algorithms via the Master Theorem?

    $$T(n) = a\,T\!\left(\frac{n}{b}\right) + f(n)$$ where $a$ is the number of subproblems, $\frac{n}{b}$ is the subproblem size, and $f(n)$ is the non-recursive work per call.

  14. What is a recursive function's 'depth of recursion' and why does it matter?

    The maximum number of nested active calls before a base case returns. It matters because each level consumes a stack frame; excessive depth causes stack overflow, and it determines the space complexity O(depth).

  15. What is the scope and lifetime of a local variable declared inside a function?

    Scope: local to the function (block scope) — visible only within it. Lifetime: automatic storage duration — created when the function is entered and destroyed when it returns (unless declared static).

  16. What does declaring a local variable static inside a function do?

    It gives the variable static storage duration: it is initialized once and retains its value between successive calls to the function, while still being visible only within that function's scope.

  17. What is a function pointer and how do you declare one that points to int f(int)?

    A function pointer stores the address of a function. Declaration: int (*fp)(int); It can be assigned fp = f; and called as fp(5) or (*fp)(5).

  18. What is a function template and how does it relate to overloading?

    A function template defines a family of functions parameterized by type, e.g. template<typename T> T max(T a, T b). The compiler instantiates a concrete function per type used, providing type-safe generic code instead of writing separate overloads for each type.

  19. What is the special role of the main function's return value in C++?

    main returns an int that is the program's exit status to the operating system: 0 (or EXIT_SUCCESS) signals success, non-zero signals failure. If no return statement is present, main implicitly returns 0.

  20. What is a constexpr function and what does it enable?

    A constexpr function is one that can be evaluated at compile time when given constant-expression arguments, e.g. constexpr int square(int x){ return x*x; }. It enables its result to be used in contexts requiring compile-time constants, such as array sizes.

  21. What is recursion's typical trade-off versus iteration for problems like tree traversal?

    Recursion offers cleaner, more readable code that closely mirrors the recursive structure of the problem (e.g. trees), at the cost of function-call overhead and stack memory. Iteration is generally faster and uses less memory but can be more complex to write for inherently recursive structures.

  22. Can inline and recursion be combined effectively?

    Generally no. Compilers typically will not fully inline a recursive function because the depth of recursion is unknown at compile time, so the inline request is usually ignored for the recursive calls.

  23. What is the difference between an lvalue reference parameter (T&) and an rvalue reference parameter (T&&)?

    T& binds to modifiable lvalues (named objects). T&& binds to rvalues (temporaries), enabling move semantics and perfect forwarding. Overloading f(T&) and f(T&&) lets a function behave differently for lvalue vs rvalue arguments.

  24. How does the compiler pass control and data during a function call at runtime (the call mechanism)?

    A stack frame (activation record) is pushed containing the return address, the arguments, and space for local variables. Control jumps to the function; on return, the return value is delivered, the frame is popped, and execution resumes at the return address in the caller.

What this deck covers

The Functions deck follows the C++ Programming Functions syllabus — 2 chapters and 7 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 25.0 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 200 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Functions flashcards FAQ

How many Functions flashcards are in this C++ Programming deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these C++ Programming flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Functions cards cover?

They follow the C++ Programming Functions syllabus — 2 chapters and 7 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.