Returns

Started by
6 comments, last by Drakon 22 years, 5 months ago
What do returns do?
"Go for the eyes, Boo, go for the eyes!"
Advertisement
They return control to the calling function.
They also return a result for non-void functions.
Could someone give me an example?
(sample code )
"Go for the eyes, Boo, go for the eyes!"
#include
#include

bool do_stuff(string name)
{
if(name == "Alex")
return true;
else
return false;
}

void main(void)
{
char tmp[50];
cout<<"Enter your name:\n";
cin.get(tmp,50);

if(do_stuff(tmp))
cout<<"Your cool!\n";
else
cout<<"You Suck!!!!";
}
#include
#include

bool do_stuff(string name)
{
if(name == "Alex")
return true;
else
return false;
}

void main(void)
{
char tmp[50];
cout<<"Enter your name:\n";
cin.get(tmp,50);

if(do_stuff(tmp))
cout<<"Your cool!\n";
else
cout<<"You Suck!!!!";
}
Oops, didn''t mean to post it twice!
Here''s an example:

  int main(){ int x = decideX();}int decideX(){ return 3;}  


Main calls on decideX, which returns 3. 3, being the result of decideX, is assigned to the int variable x. Control is returned to main().
---signature---People get ready.I'm ready to play.

This topic is closed to new replies.

Advertisement