What is the practical use of a C++ pointer?? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

What is the practical use of a C++ pointer??

30th Oct 2016, 9:03 AM
Hayden Lee
5 Antworten
+ 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.
30th Oct 2016, 9:37 AM
Nityanand sharma
Nityanand sharma - avatar
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...
30th Oct 2016, 9:15 AM
Dima Simonishvili
Dima Simonishvili - avatar
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
30th Oct 2016, 10:52 AM
Hayden Lee
0
Efficient use of Memory and also your program will run faster
30th Oct 2016, 3:08 PM
மனோஜ்குமார் பழனிச்சாமி
மனோஜ்குமார் பழனிச்சாமி - avatar
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.
1st Nov 2016, 7:13 AM
Nityanand sharma
Nityanand sharma - avatar