Difference between return and printf in C
Characteristics | return | printf |
---|---|---|
Purpose | Used to terminate the function and return a value | Used for formatted output to console |
Return Type | Depends on the function’s declared return type | int – returns the number of the characters printed |
Usage | Inside functions to return a value to the caller | Inside functions to display data on the console |
Value Passing | Passes a value from the function back to the caller | Does not pass data between functions only displays the output |
Terminates Function | Immediately exits the current function | Does not terminate the function execution continues |
Example |
return 42; returns the integer value 42 |
printf(“Hello, World!”); displays “Hello, World!” |
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