English
Summary
Conclusions
A function should have clear inputs, a result and defined side effects. A value isolates local work, a reference allows changing the original, and a const reference allows reading without a copy. Overloading and default arguments simplify calls only when they do not create ambiguity. Recursion requires a base case, reduction of the problem and an estimate of resources.
Self-check questions
- How does an argument differ from a parameter?
- How does a declaration differ from a definition?
- Why is return not console output?
- When does changing a parameter change the caller’s argument?
- Why is const T& useful for a large object?
- Why do parameter names not distinguish overloads?
- Why is the return type not a sufficient difference?
- Where are default arguments allowed?
- When is a structure better than several output parameters?
- What does a structured binding do?
- Why is it dangerous to return a reference to a local object?
- How does constexpr differ from mandatory compile-time evaluation?
- What is the base case in the Towers of Hanoi?
- How does the number of calls differ from the stack depth?
- How is argc checked before reading argv?
Review questions for the lab
- Which functions of your program change their arguments?
- How do a declaration and an implementation differ?
- Why can an overload not be selected by its result?
- When is an output parameter inferior to a structure?
- What risks does a reference to a local variable have?
- What is static_assert useful for?
- What is the base of the chosen recursion?
- How can you limit its resources?
- Why is it necessary to check argc?
- How is a complete numeric token checked?