+ 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.
8 Réponses
+ 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.
+ 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).
+ 6
So it is just for memory management, right?
Thanks for clarifying.
+ 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)
+ 2
pointers are often demonstrated in challenges because it is the difficult bit to understand about cpp :-p
+ 2
in a way, you could say that.
+ 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). 🙂