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.
✗ Incorrect
Passing by value means the function works with a copy, so the original variable stays unchanged.
How do you declare a function parameter to be passed by reference in C++?
Aint &x
Bint x
Cint *x
Dint x = 0
✗ Incorrect
Using & after the type declares a reference parameter, allowing the function to modify the original variable.
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.
✗ Incorrect
Default parameters let the caller skip some arguments, using predefined default values instead.
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);
✗ Incorrect
The correct syntax assigns a default value after the parameter type and 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
✗ Incorrect
int *ptr means the function receives a pointer to an int, allowing indirect access to the variable.
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.
Practice
(1/5)
1.
What is the purpose of function parameters in C++?
easy
A. To send data into functions so they can use it
B. To define the return type of a function
C. To declare variables inside the function body
D. To specify the function's name
Solution
Step 1: Understand function parameters
Function parameters are variables listed in the function definition that receive values when the function is called.
Step 2: Identify their purpose
They allow the function to work with different data each time it is called, making the function flexible and reusable.
Final Answer:
To send data into functions so they can use it -> Option A
Quick Check:
Function parameters = input data for functions [OK]
Hint: Parameters pass data into functions for reuse [OK]
Common Mistakes:
Confusing parameters with return types
Thinking parameters declare variables inside function body
Believing parameters define function name
2.
Which of the following is the correct syntax to declare a function add that takes two int parameters a and b?
easy
A. int add(int a, int b);
B. int add(a int, b int);
C. int add(int a; int b);
D. int add(int a b);
Solution
Step 1: Recall correct parameter syntax
In C++, parameters are declared as type name pairs separated by commas inside parentheses.
Step 2: Check each option
int add(int a, int b); correctly uses int a, int b. Options A, B, and C have syntax errors like missing comma, wrong order, or semicolon.
Final Answer:
int add(int a, int b); -> Option A
Quick Check:
Parameters = type name, comma separated [OK]
Hint: Parameters need type and name, separated by commas [OK]
How would you call this function to calculate the area of a rectangle with width 5.0 and height 3.0, and store the result in a variable result?
hard
A. double result = area(width=5.0, height=3.0);
B. double result = area(3.0, 5.0);
C. double result = area(5.0, 3.0);
D. double result = area(5, 3);
Solution
Step 1: Understand parameter order and types
The function expects width first, then height, both as doubles.
Step 2: Check each call option
double result = area(5.0, 3.0); passes 5.0 as width and 3.0 as height correctly. double result = area(3.0, 5.0); swaps them. double result = area(width=5.0, height=3.0); uses invalid named arguments (not supported in C++). double result = area(5, 3); passes ints which convert but less precise.
Final Answer:
double result = area(5.0, 3.0); -> Option C
Quick Check:
Call with correct order and types [OK]
Hint: Match argument order and types exactly [OK]
Common Mistakes:
Swapping argument order
Using named arguments (not valid in C++)
Passing wrong types without conversion
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.