What is the use of pointers when we can simply use = for doing the same thing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the use of pointers when we can simply use = for doing the same thing

3rd Sep 2022, 3:27 PM
Aditya Paswan
Aditya Paswan - avatar
2 Answers
+ 2
Pointers are to variables as variables are to values. If you understand why we use variables, then take that understanding to the next level. We use variables so that we can operate on any value without knowing which specific value is stored in the variable (variable is shorthand for variable value). Now suppose we wish to manipulate any variable without knowing which specific variable it is. That is how pointers are useful - to make variable variables. More than that, you can use pointers to make variable data structures and variable functions, too, when you won't know which function will get called until run time.
3rd Sep 2022, 5:27 PM
Brian
Brian - avatar
+ 1
You will use pointers when you will need to write a function that modify a lot of variables and the simplest way to do it is by giving to function information where variable is, and that is pointer. Next, you will need pointers for linked list. Each element of this list points with pointer to the next element, so you can change size of list or use diffrent type of elements. You will also need pointers for memory managment, if you will reserve some memory you will get a pointer to this. And the best way to get to that memory is to use that pointer.
3rd Sep 2022, 4:09 PM
Jan