This: “++” is the increment operator specific to C. Using this operator, C++ is an incremented version of C language. It is inspired from Simula and is C with classes. It was created to improve productivity of C developers.

History of C

  1. During 1970 Dennis Ritchie created C Programming language.
  2. Bjarne Stroustrup identified that this OOP features can be included in the software development.
  3. C++ Development started in 1979
  4. Versions: Visual C++, Turbo C++, ANSI C++

Influences

C++ has influenced creation of a large language family: C#, Java, Swing, GO, Rust, D, JavaScript. All these languages use a similar syntax that is called “curly languages” due to usage of curly brackets {…} for delimitation of code blocks.

Syntax

Be prepared to enter a world of symbols and weird notations that sometimes are related to math but most of the time are pure innovations. If you can memorize these notations you are half way through. The other half is learning the keywords.

Comments

This is the most simple to learn. In C++ we have line comments and block comments. You need comments in a program for two purposes: One is to document the code and second is to comment out some code for debugging purposes. Comments are ignored by the compiler.

/* 
This comment is a block comment. 
It can be on many lines.
*/
// This is a simple line comment

Note: The comments use two symbols that are also mathematical operators: / is division and * is multiplication. However the compiler is smart enough to know that two symbols “//” represents comments while a single symbol “/” represents division.

So this was not hard. But if we create a program only with comments it will nod do anything. So first thing we can do is to print something to the console. Next I will present the syntax for this so be prepared for a surprise.

Console Output

In Python we just use function print(“hello”) but in C++ we have the most weird notation possible: “cout” is the “console output” object. << is the output operator and “” is a string. So we feed from from left to right into console.

cout << "c++ is complicated";

Note: This symbol << is also bit shift left operator. What it does is not important. It was just a poor choice to use the same symbol for two things that have nothing to do with each other. When you learn C++ you will find this can be confusing, but I will point out the mistakes you have to endure to be able to learn the language properly.

Keywords

The only way to learn something is to memorize. You can memorize in two ways: The hard way and the easy way. The hard way is to understand first then memorize. The easy way is to memorize first then understand. Both are good.

I will give you a list of C keywords. Do not try to memorize this, just read and observe. Most of the keywords are English words or abbreviations. Once you have master all these keywords you have finished to learn C. These are also good for C++.

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
continueforsignedvoid
doifstaticwhile
defaultgotosizeofvolatile
constfloatshortunsigned

Symbols

There are not many symbols that we can use in C.  These symbols can be used alone or combined in pairs of two. Some symbols are operators, some symbols are used as separators. Together they form language _punctuation_.

,<>._
();$:
%[]#?
&{}
^!*/|
\~+

Note: For some reason we do not use symbol: @ in C.

If you had the patience to read up to here then is a good sign. It means you really wish to learn C++. Keep reading. I promice there is an adventure waiting for you. At the end of the journey you will be another person. A grown up software developer. A hero with shield and sword.

Program Structure

Now let’s learn some more about a simple C++ program:

#include <iostream>
using namespace std;

// main() is where program execution begins.
int main() {
   cout << "Hello World"; // prints Hello World
   return 0;
}

This program can be saved as file: hello.cpp. This is the source file of the program. Before you can run this program you have to compile and then you can run the executable file produced by the compiler.

First line: (#include) is a compiler directive. <iostream> is a “header file”. Header files are like a library file. It contains specification of public members. Header file have extension *.h;

Second line: (using namespace) is to allow “std” members to be used without the “std::” member notation (prefix) that is otherwise required for “cout” like this: std::cout;

Third line: Is a comment starting with (//) and ending at the end of the line.

Next line: int main() {…}  declare  the main function. Every C++ program must have a main function that is found by the operating system and executed when we run a program;

Return keyword is used to stop the main function and return a signal (0) to the operating system. This can be also -1 or greater than 0 to signal an error.

Statement

Usually each program line in C++ terminate with “;”.  Sometimes the program line is long and span several lines. Sometimes on a single line we can have multiple statements separated by “;”.

Multiple statements can be considered a group or block. The block is enclosed with curly brackets {…}. These blocks can be nested. We have statements that can have one or more blocks of code.

Regions

A program is created using source files. In the source file we have many statements executed from top to bottom. The program file is divided in invisible regions. These regions are: import region on top, then declaration region then the implementation region.

If you already have learned Level this can be very familiar to you. Level has “visible regions”. The main difference is that C++ regions are implicit. They belong to the program but there is no “program” keyword to show you this belonging. Just the fact they are together in the same file with the main() function that means they belong to the main program.

Learn next: CPP Data Types