Articles

C++ Return command

February 19, 2005 at 18:02:02
Specs: XP Home, 512 MB

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

See More: C++ Return command

Report •


#1
February 20, 2005 at 05:54:50

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


Report •

#2
February 20, 2005 at 22:45:19

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


Report •

#3
March 28, 2005 at 14:16:04

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


Report •

Related Solutions


Ask Question