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

//include headers; these are modules that include functions that you may use in your
//program; we will almost always need to include the header that
// defines cin and cout; the header is called iostream
#include <iostream>

using namespace std;

int main()
{
  // print output to user
  cout << "Hello World!" << endl;
  return 0;
}

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?
    $ g++ hello.cpp –o hello

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

  • How to execute?
    $ ./hello

 

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*