+ 1

Does main function have to have it datatype?

11th Nov 2018, 7:57 AM
Aashutosh Swami
Aashutosh Swami - avatar
4 odpowiedzi
+ 5
Though it gets compiled and runs but the compiler will warn about the lack of return type. So, yes it's better to be specified otherwise the compiler issues a warning (-Wreturn-type) like "ISO C++ forbids declaration of 'main' with no type" And having a warning is something smelly in a source code! 8D
11th Nov 2018, 8:11 AM
Babak
Babak - avatar
+ 5
"Can it have void return type" In pre-standard C, yes. But as far as the standard concerns: In C++ "It shall have a declared return type of type int [...]" In C "It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } "
11th Nov 2018, 8:33 AM
Babak
Babak - avatar
+ 2
Thanks
11th Nov 2018, 10:05 AM
Aashutosh Swami
Aashutosh Swami - avatar
+ 1
Can it have void return type
11th Nov 2018, 8:22 AM
Aashutosh Swami
Aashutosh Swami - avatar