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!!

See this for namespaces. For difference between <iostream> and <iostream.h> see this.

>>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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.