I was going through (Week 2> Section>Variables and Scope) when I wrote this piece of code : `

int set_int(int x);

void set_array(int array[4]);

int main(void)
    int a = 10;
    a = set_int(a);
    int b[4] = {0, 1, 2, 3};
    printf("%d, %d\n", a, b[0]);

int set_int(int x)
    x = 22;

void set_array(int array[4])
    array[0] = 22;

BTW this is a little bit bad designed, I must admit :P.

Anyway, why when I try to compile it it give me an error with the int set_int code and it prints this whenever I try to compile it :

error: control reaches end of non-void function [-Werror,-Wreturn-type]

Nonetheless, if I delete the set_int code, the set_array works fine. Thank you in advance :)

1 Answer 1


Function set_int has return type of int and in the Definition you dont return explicitly. As your error states end of non void function. A non void function must have a return Statement in the Definition otherwise Compiler will complain.

BTW, you have more Problems with your code, at the Moment I just want to stick what you have mentioned. good luck.

  • Thank you very much for your answer, it works fine now after I put a return statement before giving value for 'x'! Can you tell me about 2-3 other problems with the code please? It'd be helpful, because that's my first week of coding and I'll try to learn from my mistakes.
    – Yaman KJ
    Jun 15, 2016 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .