0

I am unable to understand return.

30th Jul 2020, 6:17 AM
Vaibhav Patel
Vaibhav Patel - avatar
4 Respostas
+ 2
As far as I can understand your question, return statement in C++ or C, (or, generally) are used when you want to send any data out of a function to the main function. so when we say a function takes two parameter and returns sum of the two numbers, ( here we didn't said it will print two number, we just said it will return ) So the logic in C/C++ will be int sum(int a, int b){ return a+b; }
30th Jul 2020, 6:48 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
It just means that the result of the method you call will return a value back to were you called it. For example int myMethod(int i){ return i+5; } //main// int j = myMethod(10); After the above statement has executed it will look like this int j = 15; because 10 was sent to the method, the method added 5 to it's current value and return it back if myMethod() was declared as "void" I would not be able to get the result back.
30th Jul 2020, 7:03 AM
D_Stark
D_Stark - avatar
0
You should be more specific while posting a question.
30th Jul 2020, 6:20 AM
Arsenic
Arsenic - avatar
0
return stops the function and return back the value to wherever the function was called.. Eg. Return n. It returns the value n from the function.
30th Jul 2020, 8:27 AM
sid
sid - avatar