Answer the question
In order to leave comments, you need to log in
What are pointers in C++?
Hello. I recently read an article about pointers on the site. They explained to me what pointers are and what they are used for.
Now I will quote the text from the site:
When executing any program, all the data necessary for its operation must be loaded into the computer's RAM. To access variables in memory, special addresses are used, which are written in hexadecimal form, for example, 0x100 or 0x200.
If there are too many variables in memory that the hardware itself cannot accommodate, the system will overload or freeze.
If we declare variables statically, as we did in previous lessons, they remain in memory until the program exits, and then are destroyed.
This approach may be acceptable in simple examples and simple programs that do not require a lot of resources. If our project is a huge software package with high functionality, declaring variables in this way, of course, would be rather unwise.
Can you imagine if the infamous Battlefield 3 used this method of working with data? In this case, the most avid gamers would have to reboot their heavily loaded systems with the reset button after a few seconds of the game.
The fact is that when playing the same Battlefield, the gamer sees various objects on the monitor screen at each new moment of time, for example, now I am shooting at the enemy, and in a split second he already falls dead, creating a lot of special effects around him, such as dust, shadows, etc.
Naturally, all this takes up some space in the computer's RAM. If you do not destroy unused objects, very soon they will fill the entire amount of PC resources.
For these reasons, most languages, including C/C++, have the concept of a pointer. A pointer is a variable that stores the address of a RAM cell, such as 0x100.
We can access, for example, an array of data through a pointer that will contain the address of the beginning of the range of memory cells that store this array.
After this array is no longer needed for the rest of the program, we simply free the memory at the address of this pointer, and it becomes available again for other variables.
Answer the question
In order to leave comments, you need to log in
If there are too many variables in memory that the hardware itself cannot accommodate, the system will overload or freeze.
Can you imagine if the infamous Battlefield 3 used this method of working with data? In this case, the most avid gamers would have to reboot their heavily loaded systems with the reset button after a few seconds of the game.
If you do not destroy unused objects, very soon they will fill the entire amount of PC resources.
Written game that has nothing to do with reality.
Moreover, the style of writing speaks of the low literacy of the author.
Read normal textbooks, not gag.
From all that has been written, in fact, it says only:
A pointer is a variable that stores the address of a RAM cell.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question