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

About pointers

Hello, could someone tell me when I will need the pointers? I understood very well, in assembler it was the only way to use the memory. But here in C ++ it seems that it is not really necessary since the variables, Arrays, etc works very well directly.

12th Jul 2020, 1:55 PM
Alain Mazy
Alain Mazy - avatar
2 Answers
+ 3
Pointers are necessary when you want to change the value of a variable from a different scope. For example when you want to pass a variable to a function and make the function change it's value, you need to pass the pointer to the variable. Also, memory management is an important aspect in C++, and when you allocate a memory location or a block of memory locations, pointers to the location is returned, and then using the pointers we can assign values to those locations.
12th Jul 2020, 2:05 PM
XXX - avatar
+ 1
Thank you both ! I had indeed realized later in the course, that it was the solution to modify the variables on the fly in the functions. & for address and * for value in the address. In the end, it's still okay.
13th Jul 2020, 11:02 AM
Alain Mazy
Alain Mazy - avatar