Hello there, I have started learning c++ and the book im reading shows different ways of writing the "hello world" programme, i just want to know how and why these are different.

#include <iostream.h>
int main ();
int main ()

{
    cout <<"hello world!!";
    return 0;
}

in this example the book says that you dont need to have the "int main();" as newer compilers automaticly does it for your or somthing.

and then it goes on replacing "<iostream.h>" with "<iostream>" in the next example but using namespace std;

#include <iostream>
using namespace std;
int main ()

{
    cout <<"hello world!!";
    return 0;
}

Soo im just wondering what the int main(); thing is about and can someone please explaing the relationship between "iostream.h and namespace std;"

im lost!!

>>what the int main(); thing is about

all functions have a return type such as int, char*, double, etc. main() is a special kind of function and is the only function required by the C and C++ standards, and it is required to return an integer back to the operating system. That return value is often used by other programs to determine whether it completed successfully or not. There is no standard value that main() must return other than it must be an integer. But by convention 0 means successfuly completion and any other value means failure.

>There is no standard value that main() must return other than it must be an integer.
Returning 0 from a program will always ensure that the correct value is sent back to the operating system to indicate success (the standard says so).

yeah, some compilers are quirky and do require
int main (); & <isotream.h>

thats why you should only use compilers that comply with the ANSI C standard

This article has been dead for over six months. Start a new discussion instead.