return statement in C++

In C++ programming language, you can't use the return statement to return a value in the function that is declared with void type. In contrast, function declared with a type rather than void must return a value of that type.

//function definitions
void printHello(){
cout<<"Hello World!"<<endl; //correct
}

int sum(int a, int b){
int s=a+b;
//No a value is returned, then you get an error.
}

int main(){

//calling the functions
printHello();
int total=sum(10,20);
cout<<total<<endl;
system(PAUSE);
return 0;
}

Posted by: Dara | post date: 12-25-2012 | Subject: C++ Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.