+ 1
What is the practical use of a C++ pointer??
5 Respuestas
+ 2
Without pointers you would lose on the ability to perform dynamic allocation of memory. What I mean is that you will not be able to allocate memory in the runtime of the program. Thus making the code less flexible.
Also pointers make it possible to make data structures like linked list and doubly linked list and stacks and queues which are used in programming a lot.
0
You can read documentation about it. I'm learning too, so I can be wrong. Pointers are giving you memory addresses where it is located. For example you want to test which memory address is bad, you'll write a program with pointers to see bad blocks...
0
Thanks for your answer! But from what I know, isn't it that we can simply implement stack, queue or linked list using the original array and some variables?? So how is pointer used in these cases
0
Efficient use of Memory and also your program will run faster
0
Stacks & queues can be implemented using arrays as well , however they limit in number of data values that can be stored.
But the very basic need for stacks and queues came out because we wanted dynamic data structures.
Thus linked list implementation ( using pointers ) allows the stack to grow and shrink at the runtime .
Also insertions and deletions in a stack are easily implemented using this way.