Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Back to Memory | References & Pointers
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C++ Intermediate | Mobile-Friendly

bookBack 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.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookBack to Memory

Swipe um das Menü anzuzeigen

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.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4
some-alt