Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Back to Memory | References & Pointers
C++ Intermediate | Mobile-Friendly
course content

Course Content

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

Back to Memory

The memory on your computer is not just chaotic units. Everything has its unique logic, and knowing it can help you optimize memory consumption. We can work with addresses and pointers to travel around the memory, and as surprising as it may sound, we have already done this!

Starting with simple math, if you add to the pointer 1 of the pointer type, for example, int or double (it also means move 4 or 8 bytes forward), you will go to the next storage unit, 1 unit forward. Sounds interesting, but where can we use it? We don’t know if something is in the next or previous memory unit, so is it useless? Actually, no. It can be used by working with arrays. We are already familiar with them and now let’s learn a new rule: each array’s element is stored in the following storage cell. For example, the 5-element integer array:

Сells of elements go one after another since an array is a contiguous memory area. With each step, we move forward by 1 integer unit (4 bytes).

To sum up, we should know only the address of the first element of the array to work with all its elements.

Everything was clear?

Section 2. Chapter 4
We're sorry to hear that something went wrong. What happened?
some-alt