Pointers | Sololearn: Learn to code for FREE!



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.

9/7/2018 1:30:04 PM


8 Answers

New Answer


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.


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).


So it is just for memory management, right? Thanks for clarifying.


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)


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☺


pointers are often demonstrated in challenges because it is the difficult bit to understand about cpp :-p


in a way, you could say that.


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). 🙂