Tutorials Navigation
C++ Beginner's Tutorial: Hello, World.
Tutorial Name: C++ Beginner's Tutorial: Hello, World.
Category: PC Tutorials
Submitted By: Nissan
Date Added:
Comments: 0
Views: 2,520
Related Forum: PC Building Forum
Share:
C++ Beginners Tutorial: Hello, World.
Your first program will be the simplest and most widely used example in learning a programming language; writing a single phrase on the screen. Seem simple? It is, but is still much more complicated than just saying it aloud! First I shall present you with the code, and then well look over it and delve into what it actually means.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
The first line tells the compiler that we want to link the iostream library to our program. A library is is a kind of repository that stores little snippets of code, called functions, that you can use. They also store other things too, such as variables and occasionally operators. More on all of that shortly. The iostream library contains code that allows us to send characters into a text stream, which is then fed into the screen. Think of it as an actual river; we are the rivers source and the screen is the sea. Whatever is put into the river from the source will go onto the screen. Maybe a bit over-analogised, but its still a good way of thinking about it. This library also lets us read this stream and modify it as it flows.
The next line tells the compiler that we want to use the namespace called std, which is the standard namespace. A namespace is a sort of area in which your code is stored. This is very useful if you want to have two pieces of code that have the same name. Normally pieces of code cannot share the same name, but if one is in one namespace and one is in the other then they can. They are in separated places, but come together in your code. If youre confused it doesnt matter, they arent really important now and well cover them in depth later. Since the iostream library uses the standard namespace, that is what we shall use.
The third line of code is the beginning of the actual code. It is the main code block, as its name implies. Everything inside those two braces ({}) is read and translated by the compiler. You will need this line in every program, because otherwise nothing will happen, and a program that does absolutely nothing is pretty useless!
Next comes the actual printing of our phrase, which in this case is Hello, World!. To do this we use some code that is stored inside the iostream library that we discussed earlier. This piece of code is called a statement, the cout, which sends some information into the stream that we discussed earlier. The << after it is called an operator. This one means output, so together with cout it means 'output the following to the stream'. The following in question is 'Hello, World!', and is called a string. A string is just a sequence of characters, and is shown by enclosing it inside double quotation marks. The cout statement doesn't just output strings though, as you will see later. It is much more powerful than that. Note that this line ends with a semi-colon (;). This signifies the end of a statement, and if not used the program will not compile.
The last line, not including the closing brace of the main code block, is simple, but important. It is always placed at the end of main (although it can be in other places as well) and tells the computer that the main block is finished; it returns a value of 0 to the CPU. A non-zero value usually denotes an error, so it is a very useful line.
Next tutorial will be on variables.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,656)
- 02. How to: Matrix Numbers | Batch File(1,954)
- 03. How to Password Protect Files on Windows(865)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,879)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,243)
- 06. How to embed an image on TheTechGame(3,140)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(13,088)
- 08. Host bot lobbies! Full Tutorial!(11,610)
- 09. Unban yourself [Plutonium BO2](14,308)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,410)
- 11. Best Crosshair Settings for Valorant(6,550)
- 12. Othercide The Surgeon Boss Guide(2,568)
- 13. Othercide Remembrances Unlock Guide(4,517)
- 14. Othercide Beginners Tips and Tricks(2,734)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,881)
"C++ Beginner's Tutorial: Hello, World." :: Login/Create an Account :: 0 comments