Note that the tutorials are displayed in order of difficulty! (From beginner to experienced.)

C++ Using functions, function parameters

Most languages allow you to create functions of some sort. Functions are used to break up large programs into named sections.

You have already been using a function which is the main function. Functions are often used when the same piece of code has to run multiple times. In this case you can put this piece of code in a function and give that function a name.

When the piece of code is required you just have to call the function by its name. (So you only have to type the piece of code once).

Let’s take a look at a simple example: More »

Posted in C++ Tutorials | 3 Comments

C++ Functions and command-line parameters

In this C++ programming tutorial we will talk some more about functions. We also will take a look at command-line parameters and function prototypes.

Command-line parameters

In some cases you want to give a parameter at the start of a program. For example: More »

Posted in C++ Tutorials | 1 Comment

C++ arrays, arrays and loops

In this tutorial, we are going to talk about arrays.

An array lets you declare and work with a collection of values of the same type. Let’s say you want to declare four integers. With the knowledge from the last few tutorials you would do something like this: More »

Posted in C++ Tutorials | 17 Comments

C++ Character sequence using arrays

In this tutorial we take a look at character sequences using arrays.

We already know that the C++ Standard Library (STL) implements a powerful string class. The string class can be used to manipulate strings of characters. But it is also possible to use plain arrays of char elements to represent a string. (Strings are in fact a sequence of characters.)

We can do the following: More »

Posted in C++ Tutorials | 1 Comment

C++ pointers – reference and dereference operators

In this tutorial we take a look at pointers. For most people it will take some time to fully understand pointers.
So you have to be patient and try to make some little programs on your own. Once you master the use of pointers, you will use them everywhere. So get ready this is a long one!

Pointers basics

To better understand pointers, it sometimes helps to compare a “normal variable” with a pointer.

When a “normal variable” is declared, memory is claimed for that variable. Let’s say you declare an integer variable MYVAR. Four bytes of memory is set aside for that variable. The location in memory is known by the name MYVAR. At the machine level that location has a memory address.

A pointer differs in the way that a pointer is a variable that points to another variable. A pointer holds the memory address of that variable. That variable contains a value. Pointers are also called address variables because they contain the addresses of other variables. More »

Posted in C++ Tutorials | 14 Comments

C++ Dynamic Memory

In this C++ programming tutorial we will take a look at dynamic memory. Until now the use of memory was determined by the size of the variable we declared. With the use of dynamic memory we can ask for a piece of memory at runtime. In C++ we can use the operators new and delete to get memory and release the memory.

new and new[] operators

With the operator new we can request a piece of memory. A data type must follow the new operator. It is also possible to request more than one element by using brackets []. The result of a new operation is a pointer to the beginning of the memory block (if the request is accepted). More »

Posted in C++ Tutorials | Comments Off on C++ Dynamic Memory

C++ structures, typedef and unions

Structures are used to group together different data elements (types of variables) under the same name. These data elements, known as members, can have different types and different lengths.

Take look at the syntax of a structure: More »

Posted in C++ Tutorials | 2 Comments

C++ Classes

In this C++ programming tutorial we take a look at classes. A class is a mechanism for creating user-defined data types. It is similar to the C language structure data type.

A class can not only hold data variables, but can also hold functions. These variables and functions are members of a class. The variables are called data members and functions are called member functions. More »

Posted in C++ Tutorials | Comments Off on C++ Classes

C++ Classes – Constructors and destructors

In the last C++ tutorial we looked at the basic concept of classes. In this C++ programming tutorial we take another look at classes.

Constructor and Destructor

Classes can have complicated internal structures, so object initialization and clean-up of a class is much more complicated then for any other data structures. Constructors and destructors are special member functions of classes that are used to construct and destroy class objects. The construction can be for example: initialization for objects or memory allocation. The destruction may involve de-allocation of memory or other clean-up for objects. More »

Posted in C++ Tutorials | 8 Comments

File IO in C++ (text and binary files)

This C++ programming language tutorial will be in two parts. The first (this one) will cover the theory behind IO and in the second tutorial we will look at some examples. More »

Posted in C++ Tutorials | 4 Comments