C++ Lesson 1: Hello World

Typically, a "Hello World" program is the most basic program you can create for a language. The purpose of the program is to print the worlds "Hello World" onto the screen.

On the left, you will find an explanation of how the source code on the right functions.

-Line 1 starts with what's known as a 'preprocessor' (#).

They are special instructions that allow for certain features to be used in a program.

The preprocessor " #include < iostream > " allows our program to utilize input and output functions, such as writing "Hello World!" to the screen.

-Line 3 is the beginning of the "main" function. Functions are small snippets of code that contain instructions for a program, and every C++ program needs a function labled "main".

Our program is contained within the brackets { } at the start and end of the main function.

-Line 7 contains the statements "cout" and "endl". cout is used to print text to the console window, and "endl" is used to move text to the next line in a console window.

-Line 8 contains a "return statement". The conditions behind these statements can be a little complex, so all we need to know for now is that our main function requires the statement "return 0" at the end.

You can copy and paste the code from the right into your own IDE, or click the "Execute" button to see the result of the program.