Key Concepts

Review core concepts you need to learn to master this subject

C++ compilation

The job of a C++ compiler is to translate the C++ program from a human-readable (high-level) form into machine understandable (low-level) form.

C++ compiler.

A C++ program is written in a human-readable form which is not understood by the machine.

A C++ compiler translates the human-readable source code into machine code.

In the example, we compile using g++. The source file first.cpp is converted to an executable machine file a.out, which is run with the preceeding ./command.

C++ compile command

The command to compile a C++ program is g++.

Execution command in c++.

In C++, the execution command is ./.

To execute a program in C++

In C++, when we compile a program an executable file is created. To execute that file we use the command ./.

If name of the executable file is a.out, we will use the command ./a.out.

C++ comments

Single-line comments in C++ are made using two consecutive forward slashes (//). Any text after // on the same line is ignored by the compiler.

Single line comments in C++.

In C++, we use // to make single line comments. The comments are ignored by the compiler. They are used for readability of the program.

C++ cout

cout is used to display the output to the standard output. It is followed by the symbols <<, which is then followed by the value to display to the standard output.

Terminating statements in C++

In C++, the semicolon ; is used to terminate a statement. Every statement in C++ must be ended with a semicolon (;), and failing to do so will result in errors thrown by the compiler.

C++ Strings

The escape sequence \n (the backslash character followed by letter n) will generate a newline, in a C++ string.

Case sensitivity in C++

C++ is case sensitive for language keywords and variable names.

Single Line C++ Comments

Comments make the code more readable for others.

In C++ , a comment starts with two forward slashes //, called a single-line comment.

The two slashes order the compiler to ignore everything that follows until the end of the line.

The code example will ignore the // single-line comment and prints the Hello world statement.

Chevron Left Icon
Hello World
Lesson 1 of 2
Chevron Right Icon
  1. 1
    There are only two kinds of languages: the ones people complain about and the ones nobody uses. C++ is a programming language created by Bjarne Stroustrup and his team at Bell Laboratories in …
  2. 2
    Take a look at the hello.cpp file in the middle of the screen. It’s a C++ program! In our text editor, you can find the file name at the top: File C++ pro…
  3. 3
    High five! We just got your first C++ program to run. C++, like most programming languages, runs line by line, from top to bottom. Here is the structure of a C++ program: ![Program Structure](htt…
  4. 4
    We learned how to output a line of text with the following code: std::cout << “Hey Jude\n”; It will output: Hey Jude We can also output multiple lines by adding more std::cout statements: s…
  5. 5
    Woohoo! You have written your first C++ programs.  –> In this lesson, you have learned: - C++ is a general purpose coding language. - C++ runs line by line, from top to bottom. - std::cout is…
  1. 1
    C++ is a compiled language. That means that to get a C++ program to run, you must first translate it from a human-readable form to something a machine can “understand.” That translation is done by …
  2. 2
    Compile: A computer can only understand machine code. A compiler can translate the C++ programs that we write into machine code. To compile a file, you need to type g++ followed by the file n…
  3. 3
    Compile: Sometimes when we compile, we want to give the output executable file a specific name. To do so, the compile command is slightly different. We still need to write g++ and the file name…
  4. 4
    Programming is often highly collaborative. In addition, our own code can quickly become difficult to understand when we return to it — sometimes only a few hours later! For these reasons, it’s ofte…
  5. 5
    Congratulations!  In this lesson, you have learned: - Compilation and execution using the terminal. g++ hello.cpp -o hello ./hello - Single line comments can be created using //. - Multi-li…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo