return in a for loop C

c, for-loop, function, return

Solution

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...

Problem

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!!:)

Original source