Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Back to Memory | References & Pointers
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.

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Posez-moi des questions sur ce sujet

Résumer ce chapitre

Afficher des exemples du monde réel

Awesome!

Completion rate improved to 2.94

bookBack to Memory

Glissez pour afficher le menu

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.

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4
some-alt