Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new programmer 1

Status
Not open for further replies.

rashrosheh

IS-IT--Management
May 3, 2002
1
JO
i cant understand the return value,can u help me?
 
EXAMPLE:

float functionCompute(int a, int b)

This is a function that does something to integer a and integer b and then returns a floating point data type when it is all through.

When your function has a return type, it is that thing that comes after the keyword "return"

functionCompute(int a, int b)
{
float answer;
answer = (float) a + (float) b;
return answer;
}

See, the object that comes after return is yours to use back in the main program. In this case, it is yours to use as a float. So you could go:

...

float someNumber;
someNumber = functionCompute(5, 6);
printf("%f", someNumber);

...

this would print the number 11

Or you could just go:

printf("%f", functionCompute(5, 6));

See? functionCompute(5, 6) is totally a floating point object because that is what is returned by the function.

The only time you don't return anything is when the function is declared as return type void.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top