0
Question about pointers and their usage.
I'm currently reading about pointers. At the moment I do not understand their practical use. I have an example that does this: int total, val; int *ptr; total = 3200; // assign 3200 to total ptr = &total; // get adress of total val = *ptr; // get value at that adress cout << "Total is: " << val; I can see what it does and how it works, but why not simple do val = total? At what point do you need or use pointers?
2 Respostas
+ 2
management of structures which are allocated memory dynamically.
It allows passing of arrays and strings to functions more efficiently. as It makes it possible to pass address of the structure instead of entire structure to the functions.
will become more clear as you encounter dynamic data structures rather than static ones, how big is a unknown user list, we wont know until users are no longer being added to it so its growing its dynamic easier to point at its last element than pass the list around. memory needs managed lol
+ 1
So it's more efficient. (and faster I assume)
Thanks for the reply. :)