What's the main use of pointers in c++ and when they are pretty useful ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the main use of pointers in c++ and when they are pretty useful ?

23rd May 2018, 1:02 PM
Oliver
3 Answers
+ 1
Often you just need to use "normal" variables, but sometimes it's more efficient to handle data via pointers. They allow you to manage the your allocated memory and let you change the value of a variable indirectly, which are both features that are often really useful. Just try coding a bit with pointers and you will better understand the advantages
23rd May 2018, 1:32 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
what about the dynamic memory ? the use of new int...
23rd May 2018, 1:37 PM
Oliver
0
They are mainly used if you allocate something on the heap, like a class or an array, you don’t really need them that often if you are just working on the stack
23rd May 2018, 1:57 PM
Max
Max - avatar