A return value is the result a function sends back to the part of the program that called it. It tells the caller what the function computed or decided.
Click to reveal answer
beginner
How do you specify the return type of a function in C?
You write the type before the function name. For example, int means the function returns an integer value.
Click to reveal answer
intermediate
What happens if a function in C does not have a return statement?
If the function's return type is not void, missing a return statement can cause undefined behavior because the function does not send back a proper value.
Click to reveal answer
intermediate
Can a function return multiple values directly in C?
No, C functions return only one value directly. To return multiple values, you can use pointers or structures.
Click to reveal answer
beginner
What is the return type of a function that does not return any value?
The return type is void. It means the function performs actions but does not send any value back.
Click to reveal answer
What keyword is used to send a value back from a function in C?
Asend
Breturn
Coutput
Dyield
✗ Incorrect
The return keyword is used to send a value back from a function.
What is the return type of a function that returns an integer?
Afloat
Bvoid
Cint
Dchar
✗ Incorrect
The return type int means the function returns an integer value.
What happens if a function declared to return int does not have a return statement?
AReturns void
BReturns zero automatically
CCompiler error
DUndefined behavior
✗ Incorrect
If a function declared to return int does not return a value, it causes undefined behavior.
Which return type means a function does not return any value?
Avoid
Bint
Cnull
Dnone
✗ Incorrect
The void return type means the function does not return any value.
How can a C function return multiple values?
AUsing pointers or structures
BUsing multiple return statements
CUsing arrays as return type
DUsing the return keyword multiple times
✗ Incorrect
C functions can return multiple values by using pointers or structures.
Explain what a return value is and why it is important in C functions.
Think about how functions communicate results back to the caller.
You got /3 concepts.
Describe how to handle returning multiple values from a function in C.
Remember C functions can only return one value directly.
You got /3 concepts.
Practice
(1/5)
1. What does the return statement do in a C function?
easy
A. It sends a value back to the place where the function was called.
B. It prints a value on the screen.
C. It declares a new variable inside the function.
D. It pauses the program execution.
Solution
Step 1: Understand the purpose of return
The return statement sends a value from the function back to the caller.
Step 2: Differentiate from other actions
Printing, declaring variables, or pausing are not what return does.
Final Answer:
It sends a value back to the place where the function was called. -> Option A
Quick Check:
Return sends value back [OK]
Hint: Return sends value back to caller, not print or pause [OK]
Common Mistakes:
Thinking return prints output
Confusing return with variable declaration
Assuming return pauses program
2. Which of the following is the correct syntax for a function that returns an integer in C?
easy
A. int myFunction() { return 5; }
B. void myFunction() { return 5; }
C. int myFunction() { print(5); }
D. myFunction() int { return 5; }
Solution
Step 1: Check function return type and return statement
The function declares int return type and returns an integer value 5.
Step 2: Identify incorrect options
void myFunction() { return 5; } returns a value but declares void (no return). int myFunction() { print(5); } uses print which is invalid in C. myFunction() int { return 5; } has wrong syntax.
Final Answer:
int myFunction() { return 5; } -> Option A
Quick Check:
Return type matches returned value [OK]
Hint: Return type must match returned value type [OK]
Common Mistakes:
Using void but returning a value
Using print instead of return
Wrong function syntax
3. What is the output of this C program?
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 4);
printf("%d", result);
return 0;
}
medium
A. 34
B. 7
C. 0
D. Error
Solution
Step 1: Understand the add function
The function adds two integers and returns their sum.
Step 2: Calculate the sum of 3 and 4
3 + 4 equals 7, which is stored in result and printed.
Final Answer:
7 -> Option B
Quick Check:
3 + 4 = 7 [OK]
Hint: Add returns sum; printed result is sum [OK]
Common Mistakes:
Concatenating numbers as strings
Confusing return with print
Expecting zero or error output
4. Identify the error in this C function:
int multiply(int x, int y) {
int product = x * y;
}
medium
A. Variables x and y are not declared.
B. Incorrect multiplication operator.
C. Function name should be void.
D. Missing return statement to return the product.
Solution
Step 1: Check function return type and body
The function declares it returns an int but does not return any value.
Step 2: Identify missing return statement
It calculates product but never returns it, causing undefined behavior.
Final Answer:
Missing return statement to return the product. -> Option D
Quick Check:
Return missing in non-void function [OK]
Hint: Non-void functions must return a value [OK]
Common Mistakes:
Forgetting to return value in non-void function
Thinking multiplication operator is wrong
Assuming variables are undeclared
5. You want to write a function that returns the maximum of three integers. Which of the following implementations correctly returns the maximum value?
hard
A. int maxOfThree(int a, int b, int c) {
if (a > b && a > c) return a;
else if (b > a && b > c) return b;
else return c;
}
B. int maxOfThree(int a, int b, int c) {
return a > b > c ? a : b > c ? b : c;
}
C. int maxOfThree(int a, int b, int c) {
int max = a;
if (b > max) max = b;
if (c > max) max = c;
return max;
}
D. int maxOfThree(int a, int b, int c) {
if (a > b) return a;
else if (b > c) return b;
else return c;
}
Solution
Step 1: Analyze int maxOfThree(int a, int b, int c) {
if (a > b && a > c) return a;
else if (b > a && b > c) return b;
else return c;
} logic
This version correctly checks if b is greater than both a and c in the else-if condition, fixing the missing cases in the original version.
Step 2: Analyze int maxOfThree(int a, int b, int c) {
int max = a;
if (b > max) max = b;
if (c > max) max = c;
return max;
} logic
This compares all values step-by-step and returns the correct maximum.
Step 3: Analyze options C and D
int maxOfThree(int a, int b, int c) {
return a > b > c ? a : b > c ? b : c;
} uses invalid chained comparison. int maxOfThree(int a, int b, int c) {
if (a > b) return a;
else if (b > c) return b;
else return c;
} misses some cases like when a is not greater than b but b is not greater than c.
Final Answer:
int maxOfThree(int a, int b, int c) {
int max = a;
if (b > max) max = b;
if (c > max) max = c;
return max;
} -> Option C
Quick Check:
Stepwise max update returns correct max [OK]
Hint: Compare stepwise and return max variable [OK]
Common Mistakes:
Using chained comparisons incorrectly
Missing some comparison cases
Returning before checking all values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.