Why Use Pointers in C?
Tomislav Kraljic
Posted on May 1, 2021
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!
💖 💪 🙅 🚩
Tomislav Kraljic
Posted on May 1, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
privacy Caught in the Crunch My Journey from Snacks to 2 Million Exposed Users Privacy
November 30, 2024
devchallenge Submission for the DevCycle Feature Flag Challenge: Feature Flag Funhouse
November 30, 2024