Computing.Net > Forums > Programming > C++ Return command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

C++ Return command

Reply to Message Icon

Name: clanmagic000
Date: February 19, 2005 at 18:02:02 Pacific
OS: XP Home
CPU/Ram: 512 MB
Comment:

Using the return command, how do i make it return to an area?



Sponsored Link
Ads by Google

Response Number 1
Name: Dark_Kartug
Date: February 20, 2005 at 05:54:50 Pacific
Reply:

What do you mean with return to an area? The return command is used to return a value from a fuction that was called. Or just to end the processing of a function. Always to return a value, unless in a function, void was specified.

Could you clarify your question a little?

Cheers,
Dark_Kartug

War sucks, but the sound is good and WE are the DJ's


0

Response Number 2
Name: Rolos
Date: February 20, 2005 at 22:45:19 Pacific
Reply:

This question has me thinking that you're a CS major newbie...

Anyhow, a short tutorial...

int area_function()
{
// Pre: none.
// Post: returns an INTEGER data type value.
int area = 5000;
return area;
}

double area_function()
{
// Pre: none.
// Post: return a DOUBLE data type value.
double area = 5000.23;
return area;
}

void area_function()
{
// Pre: none.
// Post: prints the area.
// void functions DO NOT return a value.
double area = 5.46;
cout << "Area is: " << area << endl;
}

In brief, if you have an integer area function, you have to return an integer value. If you have a double area function, you have to return a double value (maybe the compiler will let you get away with returning an integer value, but it seems as if you're only a beginner, so don't worry about this implication for now). Void type functions do not return a value.

Big hint:

int main()
{
return 0;
}

What is main()? It's an integer type function. What does it return? An integer value, 0. Does that make sense? Let us know if this has clarified some things for you.

- Rolos


0

Response Number 3
Name: learner811
Date: March 28, 2005 at 14:16:04 Pacific
Reply:

In you function
double area_function()
you "return" a local varible "area". Can you make sure the value of "area" will be returned?

Is that means function copy the "area" to the return address first, then release the memory in stack?

Could you explain more about the detail when "return" happens

Thanks
Bing


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Looking For CamStudio Cod... The error that haunts me....



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Return command

Need Help With C++ cin command www.computing.net/answers/programming/need-help-with-c-cin-command/12174.html

accessing BASH commands using c++ www.computing.net/answers/programming/accessing-bash-commands-using-c/7989.html

Return two values in C language www.computing.net/answers/programming/return-two-values-in-c-language/13620.html