Pointers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Pointers

I have completed C++ course and there was about pointers. The question I have is what is the use of pointers and why cant we find them in other languages like java and python.

7th Sep 2018, 1:30 PM
Seniru
Seniru - avatar
8 Answers
+ 5
also in cpp, if you want objects to be stored in heap rather than stack, you have to use pointers. that's the cpp way. In java you don't have the choice, what you see as an object is actually a reference (a pointer) and only java primitive types can potentially be in the stack.
7th Sep 2018, 2:47 PM
ifl
ifl - avatar
+ 6
java or python is not "better", it's different : in java, the memory management is handled by the engine. so the programmer does not have to. In some case it is a disadvantage (less control) in some other case it is good (less hassle).
7th Sep 2018, 2:42 PM
ifl
ifl - avatar
+ 6
So it is just for memory management, right? Thanks for clarifying.
7th Sep 2018, 3:04 PM
Seniru
Seniru - avatar
+ 4
java and python where invented after C++. In those languages, the notion of pointer is hidden and direct memory management is replaced by Garbage Collection. This is because those concepts are often at the source of many programming errors and it is not needed in a lots of real life applications. (In the type of applications where memory management need tighter control, languages such as C and C++ are still being used)
7th Sep 2018, 2:04 PM
ifl
ifl - avatar
+ 3
ifl so the only use of it is memory management? But i have seen pointers used for different functions in challenges and some programmes? java or python or any other languages better than cpp in memory management? Thank u☺
7th Sep 2018, 2:38 PM
Seniru
Seniru - avatar
+ 2
pointers are often demonstrated in challenges because it is the difficult bit to understand about cpp :-p
7th Sep 2018, 2:42 PM
ifl
ifl - avatar
+ 2
in a way, you could say that.
7th Sep 2018, 3:39 PM
ifl
ifl - avatar
+ 2
You can use pointers to return variables of type array, struct or multiple singular variables at once. You can use them also to call functions which you select dynamically or create templates, or work with dynamic arrays, or lists, double lists, queue, etc. It seems you still don't know to much about the power of pointers. There also exist n-pointers (double, triple, etc. pointers). 🙂
7th Sep 2018, 7:11 PM
Vasile Eftodii
Vasile Eftodii - avatar