0
0
C++programming~5 mins

Return values in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a return value in C++?
A return value is the result a function sends back to the part of the program that called it. It lets the function give information after finishing its task.
Click to reveal answer
beginner
How do you specify the type of a return value in a C++ function?
You write the type before the function name. For example, int means the function returns an integer number.
Click to reveal answer
intermediate
What happens if a function has a return type but no return statement?
If a function promises to return a value but does not use return, the program may behave unpredictably or cause an error.
Click to reveal answer
intermediate
Can a function return multiple values directly in C++?
No, a function returns only one value directly. To return multiple values, you can use structures, classes, or output parameters.
Click to reveal answer
beginner
What does the void return type mean?
It means the function does not return any value. It just performs actions without sending back a result.
Click to reveal answer
What keyword is used to send a value back from a function in C++?
Areturn
Bsend
Coutput
Dyield
If a function is declared as int add(), what must it do?
AReturn a string
BReturn nothing
CReturn an integer value
DPrint output only
What is the return type of a function that does not return any value?
Aint
Bvoid
Cnull
Dnone
Which of these can a C++ function return directly?
AOne value
BMultiple values
CNo values and multiple values
DMultiple values without any container
What happens if a function with a non-void return type does not have a return statement?
AReturns zero automatically
BReturns a default string
CReturns void
DUndefined behavior or error
Explain what a return value is and why it is important in C++ functions.
Think about how functions share results with the rest of the program.
You got /3 concepts.
    Describe how to handle returning multiple pieces of information from a C++ function.
    Consider containers or references to send back more than one value.
    You got /3 concepts.