Return Statement
In C, return is a statement used within a function to terminate the function’s execution and return a value to the caller. It is used to pass data back from the function to the calling code.
Syntax
return value;
Example
C
// C program to illustrate the return statement #include <stdio.h> // function that return value int foo() { return 10; } // driver code int main() { int z = foo(); printf ( "The value returned by function: %d" , z); return 0; } |
Output
The value returned by function: 10
Difference between return and printf in C
In C programming, return and print serve fundamentally different purposes and they are used in distinct contexts to achieve specific tasks. Let’s see each of them and see what are their functions and differences.
Contact Us