Answers for "int main() function"

C++
1

int main() {

#include <iostream> 
using namespace std;

int main () 
{
   cout << "Hello World";
}
Posted by: Guest on September-06-2021
0

void main(), main(), int main()

void main() { ... } is wrong. If you're declaring main this way, stop. (Unless
your code is running in a freestanding environment, in which case it could 
theoretically be correct.)

main() { ... } is acceptable in C89; the return type, which is not specified, 
defaults to int. However, this is no longer allowed in C99. Therefore...

int main() { ... } is the best way to write main if you don't care about the 
program arguments. If you care about program arguments, you need to declare 
the argc and argv parameters too. You should always define main in this way.
Omitting the return type offers no advantage in C89 and will break your code
in C99.
Posted by: Guest on March-21-2022

Browse Popular Code Answers by Language