0
Can anybody tell me the difference between print and return with example? (i am a newbie here Help!!!)
3 Respostas
+ 2
The print function is used for displaying output to the user on-screen. And If you want to use any value from a function into another function then you would use return.
Here is an example-
#include <stdio.h>
int sum(int a, int b){
int s = a+b;
return s;
}
int main(){
int a=6,b=7;
int summation = sum(a,b);
printf("%d\n",summation);
return 0;
int k = 5;
printf("%d",k);
}
Here you can see, we returned the value of s so that we can use it in another function called main. In the main, we used the print() function to display the value.
After return statement function will terminate and doesn't evaluate line after it. Here printing k will be got ignored.
+ 2
the print output value to the screen am sure you have use that, but the return statement return a value back to the caller, like i send you on an errand to buy me a book, i give you money which is the argument and you return a book which is the return value, in this case am the caller which send you on an errand and who you must deliver to, i hope you get that
+ 1
Print: show text on screen
Return: bring back a value from function