🌍 C++ Programming · subject
C++ Programming Functions Syllabus
Every chapter and topic of Functions examined in C++ Programming — 2 chapters, 7 topics, plus 50 flashcards written against it.
Functions syllabus — full chapter and topic list
Expand any chapter to see its topics and sub-topics. This is the whole examinable outline for Functions in C++ Programming, not a summary of it.
-
Function Basics
3 topics- Function Declaration and Definition
- Function Parameters and Arguments
- Return Types
-
Advanced Function Concepts
4 topics- Inline Functions
- Function Overloading
- Default Arguments
- Recursion
Functions flashcards for C++ Programming
24 of 50 cards from the Functions deck — real questions with worked answers.
What is the difference between a function declaration and a function definition in C++?
A declaration (function prototype) specifies the function's name, return type, and parameter types but has no body, e.g. int add(int, int); A definition additionally provides the body containing the executable statements, e.g. int add(int a, int b) { return a + b; }
What three parts make up a function's signature in C++?
The function name and the number, types, and order of its parameters. The return type is NOT part of the signature (which is why you cannot overload on return type alone).
What is a function prototype and why is it used?
A prototype is a declaration that tells the compiler a function's name, return type, and parameter types before its use. It lets you call a function before its full definition appears and enables type checking of arguments.
In C++, what does a function declared with an empty parameter list, e.g. void f();, mean compared to C?
In C++, void f(); means the function takes no parameters (equivalent to void f(void);). In C, an empty parameter list means an unspecified number of arguments.
What is the difference between a parameter and an argument?
A parameter (formal parameter) is the variable named in the function definition. An argument (actual parameter) is the concrete value or expression passed to the function when it is called.
Describe pass-by-value in C++ and its effect on the caller's variable.
The function receives a copy of the argument's value. Modifications to the parameter inside the function do NOT affect the original variable in the caller.
Describe pass-by-reference in C++ and give its syntax.
The parameter is declared as a reference, e.g. void inc(int& x). It becomes an alias for the caller's variable, so changes inside the function DO affect the original argument. No copy is made.
What is pass-by-pointer and how does it differ from pass-by-reference?
Pass-by-pointer passes the address of a variable, e.g. void inc(int* x), and the function dereferences it (*x). Unlike a reference, a pointer can be null and can be reassigned to point elsewhere; a reference must bind on initialization and cannot be rebound.
Why use a const reference parameter, e.g. void print(const std::string& s)?
It avoids the cost of copying a large object (efficiency of pass-by-reference) while guaranteeing the function cannot modify the caller's argument (safety of pass-by-value).
When an array is passed to a function in C++, what is actually passed?
The array decays to a pointer to its first element. The function receives the address, not a copy, and the array's size information is lost (which is why size is usually passed separately).
What is the purpose of a function's return type, and what does void indicate?
The return type specifies the type of value the function sends back to the caller via a return statement. A return type of void indicates the function returns no value.
What happens in a non-void function if control reaches the end without a return statement?
It results in undefined behavior. The function is required to return a value of its declared type on all paths (except main, which implicitly returns 0).
Can a C++ function return a reference? Give one caution.
Yes, e.g. int& at(int i). Caution: never return a reference (or pointer) to a local automatic variable, because that variable is destroyed when the function returns, leaving a dangling reference.
What does the auto return type combined with trailing return syntax look like, e.g. for adding two values?
auto add(int a, int b) -> int { return a + b; } Here auto with -> specifies the return type after the parameter list; in C++14 auto add(int a, int b) can deduce the return type automatically.
What is an inline function in C++ and what does the inline keyword request?
An inline function is one where the inline keyword requests the compiler to replace the function call with the function body at the call site, potentially eliminating call overhead. It is a request/hint, not a command.
State two benefits and two drawbacks of inline functions.
Benefits: eliminates function-call overhead (stack setup, jump) and can enable further optimization. Drawbacks: can increase code size (code bloat) if the function is large or called many times, and may reduce instruction-cache performance.
Besides speed, what important role does the inline keyword play with respect to the One Definition Rule?
An inline function may be defined identically in multiple translation units (e.g. in a header included by many files) without violating the One Definition Rule; the linker merges the definitions into one.
Are member functions defined inside a class body inline by default?
Yes. A member function whose body is written inside the class definition is implicitly treated as inline.
Give two reasons a compiler may refuse to actually inline a function marked inline.
Common reasons: the function is too large or complex, it is recursive, it contains loops, it takes its own address, or contains a static local variable. The compiler is free to ignore the inline request.
What is function overloading in C++?
Defining multiple functions with the same name in the same scope but with different parameter lists (different number, types, or order of parameters). The compiler selects the correct one based on the arguments.
On what parameter differences can functions be overloaded?
On the number of parameters, the types of parameters, and the order of parameter types. They cannot be overloaded solely on the basis of differing return types or by making a parameter const-by-value.
Why can't two functions be overloaded when they differ only in return type?
Because the return type is not part of the function signature. The compiler resolves overloads using the arguments at the call site, which do not convey the expected return type, so it could not disambiguate the calls.
What is overload resolution?
The compile-time process by which the compiler examines the arguments of a call and selects the best-matching overloaded function, considering exact matches, promotions, standard conversions, and user-defined conversions.
What is an ambiguous call in overload resolution, and what is the result?
When two or more overloads are equally good matches for the given arguments (no single best match), the call is ambiguous. The compiler reports a compile-time error.
Planning Functions for C++ Programming
Functions is about 11% of the C++ Programming syllabus by topic count — 7 of 65 topics, spread over 2 chapters. At roughly 45 minutes per topic plus 12 minutes per sub-topic, a first pass runs to about 5 hours.
Work top-down: read the chapter, then tick topics off individually rather than marking the whole chapter done. Sub-topics are where silent gaps hide.
Functions (C++ Programming) FAQ
What is in the C++ Programming Functions syllabus?
Functions is split into 2 chapters — Function Basics and Advanced Function Concepts, containing 7 topics and 0 sub-topics in total.
How many chapters are there in Functions for C++ Programming?
2 chapters. Functions accounts for about 11% of the topics in the whole C++ Programming syllabus (7 of 65).
How long should I spend on Functions for C++ Programming?
Budget around 5 hours for a first pass through Functions — about 45 minutes per topic plus 12 minutes per sub-topic across its 7 topics. Add revision cycles on top.
Are there flashcards for C++ Programming Functions?
Yes — a 50-card Functions deck. Sample cards are printed on this page, and the full deck is free in the Examius app with spaced repetition scheduling.