C++ Hello World program






When learning a new language, the first program people usually write is one that salutes the world 🙂

Here is the Hello world program in C++.

After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax

  • if it finds errors, it lists them
  • If there are no errors, it translates the C++ program into a program in machine language which you can execute

Notes

  • what follows after // on the same line is considered comment
  • indentation is for the convenience of the reader; compiler ignores all spaces and new line ; the delimiter for the compiler is the semicolon
  • all statements ended by semicolon
  • Lower vs. upper case matters!!
    • Void is different than void
    • Main is different that main
  • How to compile?

    compiler-generated executable file
    hello
    source file
    hello.c
    compiling command
    g++
    Note: the default output filename is “a.out”
  • How to execute?