
Hi Sanskriti,
Great question. A function doesn’t need a return statement to run, but whether or not you use it depends on what the function is supposed to do.
If a function is only doing a task (like printing something or updating a value) and isn’t meant to give anything back, you don’t need a return value — that's when you define it with void.
But if you want the function to send a result back to the place it was called from, you need a return statement.
Here’s an example:
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 5);
printf("%d", result); // Output: 8
return 0;
}
The add function returns the sum of two numbers. That return value is stored in result and printed. Without return, the function wouldn’t send anything back, and you'd have nothing to work with.
Also, if you declare a function to return a value (like int, float, etc.) but forget to use return, you might get incorrect results or even undefined behavior.
So in short:
Use
returnwhen you need a result from the function.Skip it if the function is just doing something and doesn’t need to report back.
If you have more questions, I’m here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
