+ 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?
3 Respostas
+ 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.
+ 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
- 4
ssssssssss