Pointers... When would we use them? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Pointers... When would we use them?

From learning pointers and dynamic memory and such, the only real thing i see pointers being isefull for is operstor overloading, but besides that where would we really use them in real life?

19th Jul 2016, 2:34 PM
Liam Woods
3 Answers
+ 2
As pointer contains a four or eight byte memory address, pointers are often used to manipulate memory or as a means to pass a big class / struct(, array) instance to a function (so the big instances don't have to be copied, only the much smaller (four or eight bytes) pointer). Nevertheless, passing big instances via pointer is "old school" / obsolete as you can pass parameters by reference which cannot be null.
19th Jul 2016, 2:43 PM
Stefan
Stefan - avatar
+ 1
Suppose, you have a function and you want to pass a list or an array from the main function. Passing the entire array wound take a lot of time and memory. Hence we pass only the pointer to an end element. Besides, pointers are used extensively while working with the heap section of the memory. Its always advisable to use pointers when you are interacting in between functions, classes and other blocks of code
19th Jul 2016, 4:41 PM
chaitanya guruprasad
chaitanya guruprasad - avatar
- 4
ssssssssss
19th Jul 2016, 3:23 PM
pezhman ahmadi
pezhman ahmadi - avatar