Here, I will outline the importance of pointers and why we should use them when building programs in C.
What is a Pointer?
- A pointer is a special variable where the value if a memory address.
Reasons to Use Pointers
- Accessing data by only variables is very limiting and expensive. With pointers, you can access any location and perform arithmetic operations with pointers.
- Pointers make it easy to use arrays and strings.
- Pointers allow you to refer to the same memory space from multiple locations. This means that you can update memory in one location and you will see the change everywhere else it is being used in the program.
- Saves space by being able to share components in your data structures.
- Pointers allow functions to modify data passed to them as variables.
- Pointers allow us to get multiple values from a function.
- Dynamic memory can be allocated according to the program use. We can save memory from static declarations.
- Pointers allow us to develop complex data structures like queues, linked lists and stacks.
- Pointers provide direct memory access. This makes our program run very fast and efficient!