Is it important to use pointers while writing a code in any language for example C-language does it utilize more memory.
Thank u
Pointers are used to store and manage the addresses of dynamically allocated blocks of memory. Such blocks are used to store data objects or arrays of objects.
Pointers are extremely important, which allows us to access addresses and manipulate their contents. Pointer is also the most complex and difficult feature in C/C++ language. If we use pointers correctly, pointers can widely improve efficiency and performance.
A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) an integer value, however an integer pointer holds the address of a integer variable.
Why do We Need Pointers in Data Structure? Optimization of our code and improving the time complexity of one algorithm. Using pointers helps reduce the time needed by an algorithm to copy data from one place to another.
Ditto SpyrosP's comment that this question is difficult to answer without going into a long discussion.
I guess my short answer would be: Are pointers absolutely necessary to programming? No. They make some problems easier or cleaner to solve, but you could always find alternative solutions. It's like asking, "Are databases important to programming?" or even "Is a multiplication operator important to programming?" Take away any one or two features and you could almost always get the job done some other way with the remaining features.
There are a number of examples where pointers are useful.
For example, pointers are very useful when we want to create an association between two or more things, all of which might be updated independently. Like, say we have a block of memory with information about a customer, and another block of memory with information about an order. The order is for some customer. We could copy all the customer information into the order block. But then if the customer information changes, we have to change it in two places. What if we are keeping several orders in memory, which might be for the same or different customers? Now if the customer information is changed, we have to somehow know which orders related to that customer, and change all of them. If we make a mistake doing this, we could have contradictory customer information.
But with pointers, we could have just one copy of the customer information, and the orders have a pointer to the customer. Then if the customer information changes, we don't need to update another copy in each order because there is no "other copy" in each order. The orders all just have a pointer to the one copy. We change one place, and magically all the other places see that same change.
You might want to get a book or find a web site about data structures to get more examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With