[try Beta version]
Not logged in

 
return (very simple quetstion)

Sep 29, 2010 at 7:24pm
for a given code, ex:

1
2
3
4
5
6
7
8
9
10
unsigned int bFunction()
{
if (!aFunction())
{
   //do something
   return this->data[index];
}
return false;
return 0;
}


The bFunction is not a boolean, so I have to include return 0 just so it compiles.

When !aFunction is true, it will execute everything and including return this->data[index]

My question: is it true that as soon as the program hits a return, the function will exit immediately once the return is successful? Meaning that return false will never execute, right?


Thank you!
Last edited on Sep 29, 2010 at 7:27pm
Sep 29, 2010 at 7:29pm
That's more or less right. If you hit a return in your program and there are no problems with types (which are usually dealt with at compile time, actually) then your function will terminate right there, meaning a return that would've occurred later will not.

-Albatross

EDIT: Albatross to the 10^2 factor in the post count, you're in the way of my having a simple 2^4. So stay there!
Last edited on Sep 29, 2010 at 7:32pm
Topic archived. No new replies allowed.