0

Is the main(); function is a must in C++?

29th Nov 2016, 7:13 PM
Pramod C Wickramasinghe
Pramod C Wickramasinghe - avatar
5 Respuestas
+ 2
Yes; main is the starting point for any C++ program. In the absence of this function, your code won't compile, as it has no idea where to make the starting point.
29th Nov 2016, 7:20 PM
Cohen Creber
Cohen Creber - avatar
+ 1
yeah
29th Nov 2016, 7:26 PM
Nima Moradi
Nima Moradi - avatar
0
As much as i know "int main" is approved by iso ...etc so new compilers will not work without that ... i am working with g++ and latest gcc version I even tryed to write my own main and tryed to define and use that as main but compiler returned error
29th Nov 2016, 10:17 PM
irajjs
irajjs - avatar
0
int main(){} is a program enrty point (with or without 2 parameters but it should never be void - int version implicitly returns 0 so you don't need to write that if you don't want to but don't use void return type as it is not part of the C++ ISO standard but a custom extension on some compilers). This means that your program will start there so it is mandatory for a program and must be present only once. That being said you can write static or shared libraries that can be used by different programs and those shouldn't contain main in their code.
29th Nov 2016, 10:29 PM
Domen Vrankar
Domen Vrankar - avatar
0
In a program many functions may return some values .. but at the end if you want to getout safely you should use return 0; otherwise .. -compiler .... -other values might affect ,,, -return 0; means success ... as it is said! I do not like these all but seems that it is the way it acts!
29th Nov 2016, 10:44 PM
irajjs
irajjs - avatar