C++ "Hello World!" Program

Let's start first C++ program with "Hello World!"
#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello World!";
    return 0;
}

Let's discuss code line by line.

  1. First line includes library iostream, which is required to handle input-output. This library need to include because it is not part of standard C++ Library. 
  2. In second line used to add namescpase. namescpase is group/region of classes, public method and public variables. Here we are using std Library, means C++ standard library.
  3. int main() is first function in C++, which will call first while execution. int is return type, which will return program status to outside world. Default return type in C++ is int. We can use void also.
  4. cout is the object of class ostream. It uses operator overloading to print "Hello World!".
  5. return 0 is status to other program from current program. 0 means successful execution. Non-zero value for error code.

1 comment: