C++ notes #1: General structure of a C++ program

#include <iostream>  is the preprocessor, it includes the iostream library, the library contains codes that enable us to use functions such as cout.

using namespace std  is included so that we do not have to type std::cout , instead of cout. The std::  can be omitted because of this.

main  is the name of the first function that will run when we run C++, essentially, the code inside the main()  function contains our program.

cout  is used to print statements to the console. It is pronounced as “c out”. The statement inside the bracket “Welcome to C++” will be printed, followed by a new line, indicated by  \n .

system("pause");  is used to pause the program, so that the program does not close immediately after return 0; . It will wait here, and user press something to proceed.

The double dash, //  is used to comment, the statement after the double dash is treated as comment and not process by C++. Every statement must end with a semicolon,  ; .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.