0
0
C++programming~5 mins

Function parameters in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are function parameters in C++?
Function parameters are variables listed in a function's definition. They act as placeholders for the values (arguments) passed to the function when it is called.
Click to reveal answer
beginner
What is the difference between a parameter and an argument?
A parameter is the variable in the function definition. An argument is the actual value passed to the function when calling it.
Click to reveal answer
beginner
How do you pass parameters by value in C++?
Passing by value means the function gets a copy of the argument. Changes inside the function do not affect the original variable.
Click to reveal answer
intermediate
What does passing parameters by reference mean?
Passing by reference means the function receives the actual variable's address. Changes inside the function affect the original variable.
Click to reveal answer
intermediate
What is a default parameter in a function?
A default parameter has a value assigned in the function declaration. If the caller does not provide an argument, the default value is used.
Click to reveal answer
What happens when you pass a parameter by value to a function?
AThe function gets the original variable, so changes affect it.
BThe function gets a copy of the argument, so changes inside do not affect the original.
CThe function cannot modify the parameter.
DThe function receives a pointer to the argument.
How do you declare a function parameter to be passed by reference in C++?
Aint &x
Bint x
Cint *x
Dint x = 0
What is the purpose of default parameters in functions?
ATo force the caller to provide all arguments.
BTo prevent the function from modifying arguments.
CTo make the function faster.
DTo allow the function to have optional arguments with default values.
Which of these is a correct function declaration with a default parameter?
Avoid greet(string name = "Guest");
Bvoid greet(string name);
Cvoid greet(string name = );
Dvoid greet(string = name);
If a function parameter is declared as int *ptr, how is the argument passed?
ABy value
BBy reference
CAs a pointer to an int variable
DAs a constant
Explain the difference between passing parameters by value and by reference in C++.
Think about whether the function can change the original variable or just a copy.
You got /4 concepts.
    Describe how default parameters work and why they are useful.
    Consider how you can call a function with fewer arguments than parameters.
    You got /4 concepts.