Why is it giving Compiler time error?

Why is it giving Compiler time error?


1. #include <stdio.h>
2. void foo()
3. {
4. return 1;
5. }
6. void main()
7. {
8. int x = 0;
9. x = foo();
10. printf("%d", x);
11. }



(1) main should return int, not void.
(2) The return type of foo() is currently void, so you can't return an int like 1 from it.
What exactly is the compile time error? The error message should be giving you clues as to what is wrong.

By the way I see more than one error, so posting the error messages would be beneficial.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int foo() // <--
{
    return 1;
}

int main() // <--
{
    int x = 0;
    x = foo();
    printf("%d", x);
}
Thank you very much for your answers :)
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

HINT: you can edit your post and add code tags.
Topic archived. No new replies allowed.