+ 1

Using void data type in C++

if you define the data type of the main function as void, I believe it shouldn't return any value. however when I try this in the compiler, it gives me an error saying int should be used.

24th Aug 2017, 9:51 AM
yogin c
yogin c - avatar
2 odpowiedzi
+ 2
main is special kind of function, because it is an entry point of a program (function where program begins). It is the standard for main to be int and return 0 to signal that no error occured during runtime.
24th Aug 2017, 11:21 AM
Jakub Stasiak
Jakub Stasiak - avatar
0
hmm..I say this because as per my college level C++ education, all the programs we wrote and compiled defined the main function data type as void. for simple programs, returning An integer was not deemed necessary. but I guess it depends on where you learn from. we used the turbo c++ compile back then.
24th Aug 2017, 11:28 AM
yogin c
yogin c - avatar