|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
What is the idea of using pointers in memory allocation? I mean why we have to use pointers?
|
|
#2
|
|||
|
|||
|
Think of the memory block as being your home.
Think of the pointer to the memory as your address or phone number. Next time you need someone to come round to your house, try doing it without telling them the address. Or try to send them a copy of your home. The pointer is returned after a successful memory allocation. It is the START of the memory block. It allows the SAME return value for all memory allocations irregadless of size, function used alloc /realloc /GlobalAlloc /new /far /calloc ect or data type.
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions. Frank Zappa |
|
#3
|
|||
|
|||
|
Pointers are very useful. Once you get a handle on them, you'll realize they're pretty much everywhere, in every language, whether or not you handle them directly.
They allow you to defeat scope. Data can be initialized in one scope, and used in another. This may sound bad at first, but in has its uses, and often is needed. Without this, you need to use extensive use of globals, which is generally considered sloppy. Similarly, they allow data to be exchanged across applications. You can't pass a variable from one app to another, since the second app doesn't have any concept of the first app's variables. Tell second app though where the data is (a pointer), and it can read it just fine. Exchanging data across apps isn't something you're likely to do at first, but today's software does it extensively. Take a look someday at all the different ActiveX, OLE, or COM controls installed on a recent Windows station: all of these work by one application hosting another and exchanging data. Pointers allow structures/classes that wouldn't be possible with only member variables. Look into linked lists, or any type of node structure. They would lose alot of their functionality if they're forced to contain all data as member variables. The list goes on. |
|
#4
|
|||
|
|||
|
Thanx to you people... Now i understood...
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Why we have to use pointers in memory allocation??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|