What is a C++ function?
A function is a named block of code that performs a task. It supports program decomposition by dividing a large problem into smaller, focused operations.
Study 5 Functions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a C++ function?
A function is a named block of code that performs a task. It supports program decomposition by dividing a large problem into smaller, focused operations.
Declaration vs. definition
A declaration introduces a function to the compiler without its body; a definition supplies the function body and specifies its behavior.
When must a function be declared?
A function declaration must be visible before a call that uses the function, unless the function definition already appears before that call.
Parameter vs. argument
A parameter is a variable listed in a function declaration or definition; an argument is the value supplied when the function is called.
What does a function’s return type specify?
The return type appears before the function name. A non-void function must return a suitable value on every path that reaches its end.
What does return do?
A return statement transfers control to the caller. With an operand, it also initializes the result of the function call.
What is local scope in a function?
Function parameters and local variables are usable only within their function or enclosing block, so they are not normally available in another function.
What is name hiding?
An inner declaration can hide a name from an enclosing scope. For example, a local value can hide a global value with the same name.
What happens in pass-by-value?
Pass-by-value gives the function its own parameter object initialized from the argument. Assigning to that parameter does not change the caller’s variable.
Why does reset(original) leave original unchanged?
Changing a pass-by-value parameter does not change the caller’s variable because the function modifies its independent parameter object.
What is function overloading?
Function overloading permits functions in the same scope to share a name when their parameter lists differ in number or types.
Can return types alone overload functions?
The return type alone cannot distinguish overloads. Two functions with identical parameter lists but different return types are invalid overloads.