Is it important to use pointers while writing a code in any language for example C-language does it utilize more memory.
Thank u
Is it important to use pointers while writing a code in any language for example C-language does it utilize more memory.
Thank u
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.
A pointer for a pointed value is like an URL for a pointed page.
Pointers are as necessary as URLs are.
About memory : an URL takes far less memory than the pointed page, it's exactly the same thing for pointers
No, pointers are not unavoidably required for a programming language. There are languages which have no pointers: Java and Python are well-known examples. Many languages adopting functional paradigm don't have a notion of (built-in) pointer.
The reason why in C you have to work with pointers is that C is relatively low-level language. It is suited best for writing firmware, drivers, OS components or performance-critical libraries. In all these areas, you are usually working a lot directly with memory blocks and addresses, and pointers are C abstraction of memory address.
It's a pretty difficult question to answer without going into a long discussion. First of all, pointers are incredibly useful and required to make a language versatile.
A very typical situation is when you want to pass a variable by reference. Meaning that you want to change its value inside a function. Passing just the variable name, would only pass its value. Instead, you have to pass a pointer, which shows the passed variable address.
Or when you have to point to a new memory created node, like a linked list node.
As far as memory is concerned, a pointer is just like another variable. Thus, if an integer variable holds 4 bytes of STORAGE(not memory), then an integer pointer for that variable holds 4 bytes of storage. It's not about memory, it's about storage.