bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/C++

C++

C++ Tutorial

C++ Tutorial focused on C++ Introduction and related concepts.

Lesson 1

C++ Tutorial

C++ is a popular programming language.

Read lesson →Loading…
Lesson 2

C++ Introduction

C++ is a cross-platform language that can be used to create high-performance applications.

Read lesson →Loading…
Lesson 3

C++ Getting Started

If you want to run C++ on your own computer, you need two things:

Read lesson →Loading…
Lesson 4

C++ Syntax

Let's break up the following code to understand it better:

Read lesson →Loading…
Lesson 5

C++ Statements

A computer program is a list of "instructions" to be "executed" by a computer.

Read lesson →Loading…
Lesson 6

C++ Output (Print Text)

The cout object, together with the << operator, is used to output values and print text.

Read lesson →Loading…
Lesson 7

C++ Output Numbers

You can also use cout() to print numbers.

Read lesson →Loading…
Lesson 8

C++ New Lines

To insert a new line in your output, you can use the \n character:

Read lesson →Loading…
Lesson 9

C++ Comments

Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.

Read lesson →Loading…
Lesson 10

C++ Variables

Variables are containers for storing data values.

Read lesson →Loading…
Lesson 11

C++ Declare Multiple Variables

To declare more than one variable of the same type , use a comma-separated list:

Read lesson →Loading…
Lesson 12

C++ Identifiers

All C++ variables must be identified with unique names .

Read lesson →Loading…
Lesson 13

C++ Constants

When you do not want others (or yourself) to change existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only ):

Read lesson →Loading…
Lesson 14

C++ User Input

You have already learned that cout is used to output (print) values. Now we will use cin to get user input.

Read lesson →Loading…
Lesson 15

C++ Data Types

As explained in the Variables chapter, a variable in C++ must be a specified data type:

Read lesson →Loading…
Lesson 16

C++ Numeric Data Types

Use int when you need to store a whole number without decimals, like 35 or 1000, and float or double when you need a floating point number (with decimals), like 9.99 or 3.14515.

Read lesson →Loading…
Lesson 17

C++ Boolean Data Types

A boolean data type is declared with the bool keyword and can only take the values true or false .

Read lesson →Loading…
Lesson 18

C++ Character Data Types

The char data type is used to store a single character. The character must be surrounded by single quotes, like 'A' or 'c':

Read lesson →Loading…
Lesson 19

C++ String Data Types

The string type is used to store a sequence of characters (text). This is not a built-in type, but it behaves like one in its most basic usage. String values must be surrounded by double quotes:

Read lesson →Loading…
Lesson 20

C++ auto

The auto keyword automatically detects the type of a variable based on the value you assign to it.

Read lesson →Loading…
Lesson 21

C++ Operators

Operators are used to perform operations on variables and values.

Read lesson →Loading…
Lesson 22

C++ Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

Read lesson →Loading…
Lesson 23

C++ Assignment Operators

Assignment operators are used to assign values to variables.

Read lesson →Loading…
Lesson 24

C++ Comparison Operators

Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.

Read lesson →Loading…
Lesson 25

C++ Logical Operators

As with comparison operators , you can also test for true ( 1 ) or false ( 0 ) values with logical operators .

Read lesson →Loading…
Lesson 26

C++ Operator Precedence

When a calculation contains more than one operator, C++ follows order of operations rules to decide which part to calculate first.

Read lesson →Loading…
Lesson 27

C++ Strings

Strings are used for storing text/characters.

Read lesson →Loading…
Lesson 28

C++ String Concatenation

The + operator can be used between strings to add them together to make a new string. This is called concatenation :

Read lesson →Loading…
Lesson 29

C++ Numbers and Strings

C++ uses the + operator for both addition and concatenation .

Read lesson →Loading…
Lesson 30

C++ String Length

To get the length of a string, use the length() function:

Read lesson →Loading…
Lesson 31

C++ Access Strings

You can access the characters in a string by referring to its index number inside square brackets [] .

Read lesson →Loading…
Lesson 32

C++ Special Characters

Because strings must be written within quotes, C++ will misunderstand this string, and generate an error:

Read lesson →Loading…
Lesson 33

C++ User Input Strings

It is possible to use the extraction operator >> on cin to store a string entered by a user:

Read lesson →Loading…
Lesson 34

C++ String Namespace

You might see some C++ programs that run without the standard namespace library. The using namespace std line can be omitted and replaced with the std keyword, followed by the :: operator for string…

Read lesson →Loading…
Lesson 35

C++ C-Style Strings

C-style strings are created with the char type instead of string .

Read lesson →Loading…
Lesson 36

C++ Math

C++ has many functions that allows you to perform mathematical tasks on numbers.

Read lesson →Loading…
Lesson 37

C++ Booleans

Very often, in programming, you will need a data type that can only have one of two values, like:

Read lesson →Loading…
Lesson 38

C++ Boolean Expressions

A Boolean expression is a piece of code that compares values or variables and returns a boolean value: 1 (true) or 0 (false).

Read lesson →Loading…
Lesson 39

C++ If ... Else

You already know that C++ supports familiar comparison conditions from mathematics, such as:

Read lesson →Loading…
Lesson 40

C++ Else

Use the else statement to specify a block of code to be executed if the condition is false .

Read lesson →Loading…
Lesson 41

C++ Else If

Use the else if statement to specify a new condition to test if the first condition is false .

Read lesson →Loading…
Lesson 42

C++ Short Hand If Else

There is also a short-hand if...else , known as the ternary operator because it uses three operands.

Read lesson →Loading…
Lesson 43

C++ Nested If

You can also place an if statement inside another if . This is called a nested if statement.

Read lesson →Loading…
Lesson 44

C++ Logical Operators in Conditions

You can combine or reverse conditions using logical operators . These work together with if , else , and else if to build more complex decisions.

Read lesson →Loading…
Lesson 45

C++ Switch

Use the switch statement to select one of many code blocks to be executed.

Read lesson →Loading…
Lesson 46

C++ While Loop

Loops can execute a block of code as long as a specified condition is reached.

Read lesson →Loading…
Lesson 47

C++ Do/While Loop

The do/while loop is a variant of the while loop. This loop will execute the code block once , before checking if the condition is true. Then it will repeat the loop as long as the condition is true.

Read lesson →Loading…
Lesson 48

C++ For Loop

When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop:

Read lesson →Loading…
Lesson 49

C++ Nested Loops

It is also possible to place a loop inside another loop. This is called a nested loop .

Read lesson →Loading…
Lesson 50

C++ The foreach Loop

There is also a " for-each loop" (also known as ranged-based for loop), which is used to loop through elements in an array (or other data structures ):

Read lesson →Loading…
Lesson 51

C++ Break and Continue

The break statement can also be used to jump out of a loop .

Read lesson →Loading…
Lesson 52

C++ Arrays

Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

Read lesson →Loading…
Lesson 53

C++ Arrays and Loops

You can loop through the array elements with the for loop.

Read lesson →Loading…
Lesson 54

C++ Omit Array Size

In C++, you don't have to specify the size of the array. The compiler is smart enough to determine the size of the array based on the number of inserted values:

Read lesson →Loading…
Lesson 55

C++ Array Size

To get the size of an array, you can use the sizeof() operator:

Read lesson →Loading…
Lesson 56

C++ Multi-Dimensional Arrays

A multi-dimensional array is an array of arrays.

Read lesson →Loading…
Lesson 57

C++ Structures (struct)

Structures (also called structs) are a way to group several related variables into one place.

Read lesson →Loading…
Lesson 58

C++ Enumeration (enum)

An enum is a special type that represents a group of constants (unchangeable values).

Read lesson →Loading…
Lesson 59

C++ Memory Address

In the example from the earlier example, the & operator was used to create a reference variable. But it can also be used to get the memory address of a variable; which is the location of where the va…

Read lesson →Loading…
Lesson 60

C++ Pointers

You learned from the previous chapter, that we can get the memory address of a variable by using the & operator:

Read lesson →Loading…
Lesson 61

C++ Dereference

In the example from the earlier example, we used the pointer variable to get the memory address of a variable (used together with the & reference operator). However, you can also use the pointer to g…

Read lesson →Loading…
Lesson 62

C++ Modify Pointers

You can also change the pointer's value. But note that this will also change the value of the original variable:

Read lesson →Loading…
Lesson 63

C++ Memory Management

Memory management is the process of controlling how much memory your program uses - and how it is used. This includes creating, using, and releasing memory when it's no longer needed.

Read lesson →Loading…
Lesson 64

C++ new and delete

The new keyword lets you manage memory yourself.

Read lesson →Loading…