What does a C++ function declaration specify?
A function declaration, or prototype, tells the compiler the function’s name, return type, and parameter types without providing its body.
Study 05 Functions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does a C++ function declaration specify?
A function declaration, or prototype, tells the compiler the function’s name, return type, and parameter types without providing its body.
What is a function definition?
A function definition supplies the complete implementation, including the function body and its statements.
How do parameters differ from arguments?
A parameter is a variable in a function declaration or definition; an argument is the actual value supplied when the function is called.
What happens when an argument is passed by value?
By-value parameters receive copies, so changing the parameter inside the function does not change the caller’s original variable.
What can a reference parameter do?
A reference parameter, such as int& value, can modify the caller’s variable directly.
Why use a const reference parameter?
A const reference avoids copying while preventing the function from modifying the referenced argument.
What does return do in a C++ function?
The return statement ends a function and can send a value back to its caller. A void function may use return; only to exit early.
What does void mean as a function return type?
A function with return type void does not return a value to its caller.
What happens during a function call?
When called, a function’s parameters are initialized from the arguments, its body executes, and control returns to the statement after the call.
What determines a local variable’s scope?
A local variable can be used from its declaration through the end of its enclosing block; it is unavailable outside that scope.
Why can a local variable reset on every call?
Each ordinary function call creates independent local variables, so a local count initialized to zero prints 1 on every call after incrementing.
What makes two C++ functions overloads?
Function overloading permits the same name for functions whose parameter lists differ in number, types, or type order.