Reputation: 35
I am trying to understand the return type function but I really can't. For example in this code:
int add(int a, int b){
result=a-(-b);
return result;
}
I cant understand why it became return result and what is it for and what it do.I am new in c++ and Iwanted to become better in c++.
Upvotes: 1
Views: 573
Reputation: 358
This is meant to give back an answer (value) to the other part of your program, which called this function.
Let's say you do something like:
print(add(2,4));
Your program would print the value: 6
Disclaimer: not really sure if the syntax is correct, it's been over a decade since I last programmed in C++;
Upvotes: 0