function pass control

Feb 7, 2012 at 9:28pm
Can anyone help me with this?....
How does a function pass control back to the calling function?
Feb 7, 2012 at 9:40pm
return data_type_of_function or in the case of void just let the function run its course
Feb 7, 2012 at 9:57pm
For functions that are declared to return nothing (void), either the function can complete or there can be "return;" somewhere.

For functions that are declared to return a value, the function must at some point "return some_value;"

For all cases, functions may throw exceptions which could be caught in a higher calling function.
Feb 8, 2012 at 9:59pm
the value though must be the data type declared with the prototype
Feb 8, 2012 at 10:06pm
@Aramil: Firstly, you don't even need to have a prototype. The actual definition determines the type that must be returned, the prototype and definition just have to match.

Second, it doesn't have to return a variable which matches the type of the return type of the function. It can, or it can return a variable that is implicitly convertible to the return type. Details matter ;)
Feb 17, 2012 at 3:56pm
thank i didnt know that. well, i mean i knew about the prototypes but are you saying something like it returns a bool and its meant to return false so it returns 1 (I believe 1 is false but i could be wrong)
Feb 17, 2012 at 4:49pm
false is defined as 0, and true is defined as "not false" (eg 1 or any other number besides 0)
Feb 22, 2012 at 3:47pm
ok ty I couldnt remember which
Topic archived. No new replies allowed.