+ 3
What is the practical use of pointers?
I get what they do, what what use does that serve?
5 Antworten
+ 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
+ 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.
+ 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.
+ 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
+ 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