> Simple C++ Program ~ Online tutorial

Simple C++ Program

A Simple C++ Program

#include <iostream.h>

int main (void)


cout << "Hello World\n";

  • This line uses the preprocessor directive #include to include the contents
    of the header file iostream.h in the program. Iostream.h is a standard
    C++ header file and contains definitions for input and output.
  • This line defines a function called main. A function may have zero or more
    parameters; these always appear after the function name, between a pair of
    brackets. The word void appearing between the brackets indicates that main
    has no parameters. A function may also have a return type; this always
    appears before the function name. The return type for main is int (i.e., an
    integer number). All C++ programs must have exactly one main functions.
    Program execution always begins from main.
  • This brace marks the beginning of the body of main.
  • This line is a statement. A statement is a computation step which may
    produce a value. The end of a statement is always marked with a semicolon
    (;). This statement causes the string "Hello World\n" to be sent to the
    cout output stream. A string is any sequence of characters enclosed in
    double-quotes. The last character in this string (\n) is a newline character
    which is similar to a carriage return on a type writer. A stream is an object
    which performs input or output. Cout is the standard output stream in C++
    (standard output usually means your computer monitor screen). The symbol
    << is an output operator which takes an output stream as its left operand and an expression as its right operand, and causes the value of the latter to be sent to the former. In this case, the effect is that the string "Hello World\n" is sent to cout, causing it to be printed on the computer monitor screen.
  • This brace marks the end of the body of main.
Buy It Now

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
Powered By: BloggerYard.Com