+ 4

Pointers(need help)

What's the use of pointers in c++? Where are they used? Any examples if possible?

16th Jan 2017, 4:25 PM
Daniel Fernandes
Daniel Fernandes - avatar
3 Answers
+ 3
when we use a variable, we first see it's memory address, and then perform the action on it. with pointers, we directly perform the operation on the memory address, hence saving us a step and making the execution faster. also, pointers and arrays are like brothers. you need pointers if you want to pass around arrays in and out of a function.
16th Jan 2017, 4:31 PM
Nikunj Arora
Nikunj Arora - avatar
+ 2
oh I get it, its for speed. thanks
16th Jan 2017, 4:50 PM
Daniel Fernandes
Daniel Fernandes - avatar
+ 1
It is not only to speed up. You need it for dynamic programming (dynamic memory allocation) and low level memory manipulations. Arrays are just pointers, so pointers are a deep concept in C and C++. You rarely need them but with pointers you can do difficult tasks with lesser code.
18th Feb 2017, 10:36 PM
Manuel Maier
Manuel Maier - avatar