Why would someone use a pointer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why would someone use a pointer?

I am a novice programming and I am currently learning C++. Most of what I have learned (variables, conditional statements, vectors, arrays, structs and by extension classes) immediately shows how and when they can be used. However, pointers currently seems like another aspect of C++ that can be ignored entirely. This is definitely not the case, so when, where, and how would an adept programmer use a pointer.

27th Jul 2019, 2:50 PM
Mike The great Sage
Mike The great Sage - avatar
9 Answers
+ 4
Imagine working on parking service where you should show people where are empty parking spots. At one point you would be pointing your finger at one position, next time another. In this case your finger is pointer. This is how I understood pointers when I started studying it at start
29th Jul 2019, 1:58 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
+ 2
Thank you for your insight, it is really helpful and appreciated
27th Jul 2019, 3:45 PM
Mike The great Sage
Mike The great Sage - avatar
+ 1
An easy tu understand example I know about is when you want to modify the direct value of a variable, vector, list, etc... in a function, take this code as an example: https://code.sololearn.com/c0AO2xjBstN7/?ref=app
27th Jul 2019, 3:31 PM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 1
That's the only useful case I know of
27th Jul 2019, 3:43 PM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 1
Check difference between - call by value and call by reference. Hope this will help u in understanding the use of pointers...!!!
27th Jul 2019, 5:05 PM
Kuri
Kuri - avatar
0
Thank you. That shows one example of using a pointer, but I am also curious as to other examples as well.
27th Jul 2019, 3:36 PM
Mike The great Sage
Mike The great Sage - avatar
0
Thank you Kuri
27th Jul 2019, 7:16 PM
Mike The great Sage
Mike The great Sage - avatar
0
That explains the importance of pointers quite a lot, thank you Edin.
29th Jul 2019, 2:33 PM
Mike The great Sage
Mike The great Sage - avatar
0
Hello ...people I still don't understand?
5th Aug 2019, 8:39 AM
Rodgers Penda