Pointers and why

So I have been reading and get the logic with how to use pointers (except for some complicated implementations like void pointers) but I was trying to grasp the why and this line I found cleared it up for me:

If you happen to have a huge piece of data that you want to pass into a function, it’s a lot easier to pass its location to the function than to copy every element of the data!

https://www.cprogramming.com/tutorial/lesson6.html

It expands on it more but I figured that would help out some others that are new to this.

I suggest you to read about dynamic memory allocation. It will definitely help you understand the true power of pointers.

Privacy & Terms