What is the practical use of pointers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the practical use of pointers?

I get what they do, what what use does that serve?

3rd Sep 2017, 11:13 PM
Thrawn
5 Answers
+ 7
As far as I know, you can use it to change the value of a variable you passed as the argument of a function
3rd Sep 2017, 11:26 PM
Dapper Mink
Dapper Mink - avatar
+ 6
When passing parameters, pointers allow you to only have to push the memory address on the stack, where as passing something like a big class would require you to push all of the member variables onto the stack, which is a very large overhead. So for performance, pointers/references should always be used when passing parameters, except for primitive types that you don't plan on changing directly.
4th Sep 2017, 12:26 AM
aklex
aklex - avatar
+ 2
The most important part is I think, you can organize your code dinamically with them. If there are a lot of structs, classes and datas there, you can easily manipulate them with the help of the pointers.
4th Sep 2017, 12:14 AM
Hajnal Máté
Hajnal Máté - avatar
+ 1
honestly its more important when u get to classes and polymorphism but it is used to point to a variable and return memory addresses
3rd Sep 2017, 11:35 PM
HJ🐓TDM
+ 1
In C++ they are not as important as in C, since you don't need to pass pointers to functions and will usually pass references instead. They're mostly used for new/delete
4th Sep 2017, 12:52 AM
Schindlabua
Schindlabua - avatar