In the following code, would anything be returned?
#include <stdio.h>
int try_this (int in);
int main (void)
{
try_this (5);
}
int try_this (int in)
{
int i = 1;
for (i = 0; i < in; i = i + 2) {
return i;
}
return i;
}
Since there's a return in the for loop, would the code just return nothing since there's nothing after the function is called? Or would i be returned as a number, like 1(because of the declaration in try_this) or 6(because of the loop)? Thank you!!:)
When the first return
statement is encountered, the function will return. It's easy to see that the function will start the loop and while i=0
it will return i
. So each time you call try_this you'll get 0
Also, return 0;
from main...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With