warning: return type defaults to ‘int’ [-Wreturn-type]

In C89, the default return type is int. This default was removed in C99 and compilers are helpful reminding you that your C-style with no int before main() is out of date.

See the C89 specification Section 3.5.2 "Type specifiers":

  • "Each list of type specifiers shall be one of the following sets: [...] + int, signed, signed int, or no type specifiers".

  • And in the second paragraph of semantics: "Each of the [...] sets designates the same type, except that for bit-fields [blabla]". So this means "no type specifiers" is the same as int.

In C99, the part "or no type specifier" is removed. (But you can still write signed without the int part.)


main()

should be

int main()

In C89, the default return type is assumed to be int, that's why it works.