Font size
WorksheetsChapter6-2
Total questions: 20
Worksheet time: 15mins
What are the methods used to pass parameters to a function in C++?
Call by memory
Call by reference
Call by duplicating the argument
Call by value
In C++ What is the symbol used to tell the compiler that you are sending a parameters to a function by reference?.
&&
@
*
&
In C++ when sending parameters by reference the & is placed.
&<Data Type>
<Data Type> & <Variable Name>
<Data Type> <Variable Name>&
<Data Type> <Constant Name>&
In C++ When passing parameters by reference to a function, you are passing:
A copy of the value in the calling function.
The value of the parameters in the calling function
The memory address of the variable in the calling function
None of the above.
In C++, If you need to send a value to a function by using parameters, and you do not need to return anything from the function, what type of call will you use:
Call by Value
Call by Reference
Call by Cellular phone
A void call
In C++, if a function receives a parameter by reference and it changes the value, what happens?.
Nothing
The value of the variable in the calling function will be changed as well
You will get a compiler error
Unlimited loop
select the correct syntax:
void func1 ( int& val1)
{
.......
}
void func1 ( &int val1)
{
.......
}
void& func1 ( int val1)
{
.......
}
&void func1 ( int val1)
{
.......
}
int &x; this syntax is used when...
x is passed by value
x is passed by reference
x is declare outside functions
None of them
Which statement is correct about passing by value parameters?
It cannot change the actual parameter value
It can change the actual parameter value
Parameter is always in read-write mode
None of them
___________ is the identifier used in a method to stand for the value that is passed into the method by a caller
formal parameter
actual parameter
functions
none of them
What is the main purpose of functions in C++?
To execute loops faster
To reduce code redundancy and improve reusability
To replace the main() function
To speed up compilation
Which keyword defines a function that does not return a value?
int
return
void
float
How do you call a function in C++?
functionName;
functionName()
call functionName();
define functionName();
What is required in a function declaration?
Function name and parameters
Only the function body
Function name, return type, and parameters (if any)
Only the return type
What will happen if a function is declared but not called?
It will cause a compilation error
It will execute automatically
Nothing will happen
The program will crash
Which of the following statements about function parameters is true?
A function can only have one parameter
Parameters are mandatory in all functions
Parameters act as variables inside the function
Parameters must be initialized in the function declaration
What is "pass by reference" in functions?
Passing values by copying them
Allowing a function to modify the original variable
Passing only integer values
Calling a function multiple times
Which function type returns a value?
void function
Function with no parameters
Function with a return type
Function with default parameters
Which statement about the return keyword is correct?
It must always be used in functions
It ends function execution and sends a value back
It only works with int functions
It can only be used once per function
What is the output of the following code: void update(int &x) { x += 10; } int num = 5; update(num); cout << num;
5
10
15
Compilation error
