+ 1

When do we use pointer? I don't get when to use it.

20th Jul 2015, 5:33 AM
Dojee Galtshen
Dojee Galtshen - avatar
6 Respostas
+ 1
I've used it when I want to change a global variable from inside a function, but want the variable that I'm changing to be an input for the function. If you just type the variable name into the input, then it'll take the value of the variable, change it, then discard it at the end of the function. If you use a pointer as the input, it will take the variable and change its value. I actually just used this to make make my program about 50 lines shorter. Very useful.
5th Nov 2015, 5:08 PM
Will Ashworth
+ 1
When you want multiple returns, for example. Or when you simply want to change the value of a variable. If you send a pointer to a variable, you can change it inside a function, and this change will be made to the original variable. If you send a variable, C++ compiler will simply make a copy of your variable. Original won't change. If you work with a large array, for example, making a copy of that array will take lots of memory. If you send a pointer, you won't need as much memory. But you risk damaging (making permanent changes to) the original array...
6th Apr 2016, 12:20 PM
Yuri Predborski
Yuri Predborski - avatar
0
When we need to use address of the memory location we use pointers
22nd Jul 2015, 7:03 PM
Gaurav
Gaurav - avatar
0
it makes calculations faster ,using d address of d value
26th Dec 2015, 11:25 AM
Tapan
Tapan - avatar
0
on dynamic programming, like arrays you must have knowledge of pointer. cause on dynamic arrays using function in c++, parameter function of arrays use pointer.
15th Apr 2016, 5:07 AM
Philip lambok
Philip lambok - avatar
0
Aside from referencing and deferencing, one of the most essential uses of pointers are for dynamic memory allocation. Dynamic memory allocation can only be done using pointers. And this dynamic memory allocation has many applications including, but not limited to, game development and artificial intelligence.
9th May 2016, 9:58 AM
Christian Collamar (Ian)
Christian Collamar (Ian) - avatar