The return statement in C is used to terminate a function and transfer control back to the calling function. It can also return a value from the function to the caller.
- The return statement ends the execution of a function.
- It may return a value or no value depending on the function's return type.
Syntax:
return return_value;
Example:
int add()
{
return 10;
}
Explanation: The function returns the value 10 to the calling function.

Return Statement in Void Functions
A void function does not return any value. Therefore, using a return statement is optional.
- Void functions do not return any value.
- The return; statement can be used to exit the function early.
Syntax Without Return Statement:
void functionName()
{
// statements
}
#include <stdio.h>
void display()
{
printf("Hello World");
}
Explanation: The function executes normally and automatically ends after the last statement.
Syntax With Return Statement:
void functionName()
{
return;
}
#include <stdio.h>
void checkNumber(int num)
{
if(num < 0)
return;
printf("Positive Number");
}
Explanation: The function exits immediately when the number is negative.
Incorrect Use of Return in Void Function
A void function cannot return a value.
Incorrect Syntax:
void display()
{
return 10;
}
void display()
{
return 10;
}
Explanation: This causes a compilation error because a void function cannot return a value.
Return Statement in Functions Returning a Value
Functions with a non-void return type must return a value of the specified type.
- A return value is mandatory in non-void functions.
- The returned value must match the function's return type.
Syntax:
return expression;
int square(int num)
{
return num * num;
}
Explanation: The function calculates and returns the square of the number.
Multiple Return Statements in a Function
A function can contain multiple return statements, but only one of them is executed during a function call.
- Multiple return statements are allowed.
- Function execution stops after the first executed return statement.
Syntax:
if(condition)
return value1;
return value2;
int findSign(int num)
{
if(num > 0)
return 1;
return -1;
}
Explanation: The function returns 1 for positive numbers and -1 otherwise.
Returning Only One Value
The return statement can directly return only one value from a function.
- Only one value can be returned directly.
- The returned value can be a variable, constant, or expression.
Syntax:
return value;
int getAge()
{
return 25;
}
Explanation: The function returns a single integer value.
Common Mistakes
1. Missing Return Statement:
int getNumber()
{
}
Explanation: Non-void functions must return a value.
2. Returning Wrong Data Type:
int getValue()
{
return "Hello";
}
Explanation: A string cannot be returned from a function with return type int.
3. Returning a Value from a Void Function:
void show()
{
return 100;
}
Explanation: Void functions cannot return values.
return; Vs return value
| Feature | return; | return value; |
|---|---|---|
| Used In | Void Functions | Non-Void Functions |
| Returns a Value | No | Yes |
| Terminates Function | Yes | Yes |
| Syntax | return; | return 10; |
| Example | return; | return num; |