question about return

0 Pranam Lashkari · July 1, 2015
why we need "return answer"? I tried to do this program without that it still works.

Post a Reply


Oldest  Newest  Rating
0 Superman HC · July 1, 2015
return answer will be helpful.. when you need the value of answer in another function in the program...
+1 ashiq sultan · July 1, 2015
hello Pranam Lashkari, 
you need to be more brief with your question because when you say "this" program you should mention what program you are working on.
0 Pranam Lashkari · July 2, 2015
C++ tutorial 11

#include <iostream>
using net space std;

int addnumber(int x, int y)
int answer = x + y
return answer;

int main()
cout << addnumber(43,86)
return 0;
0 ANURAG SINGH · July 2, 2015
you need to  type 'return" in programs if your main program body's prototype starts with "int main".
ortherwise if its "void main" is not neccesary.
hope this was useful :)
0 c student · July 3, 2015
you need to return because main does not have direct access to the variables inside other functions.  returning allows main obtain these values.
0 Arif Ullah · July 3, 2015
void addnumber(int x, int y)
int answer = x + y
return answer;


void main(){
     addnumber(10,15);//call function and function parameter x=10 , y=15
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator