Help with the Heap
As you would guess from my question, I am a complete noob.I have a question about Heaps. They are made so that a variable is defined in one function and used in another, I noticed that this variable is a pointer, is it always a pointer, or could it be any other type?
Heap is something from which you can allocate memory (ofcourse at run time)
The memory can be allocated only to pointer variables.
Pointer is a variable which points to a location in the heap.
You get a segmentation fault when you access the pointer which has not been allocated any memory or is pointing nowhere.
You're either describing a global variable there which is in what some call the data segment, or a local variable which is simply on the stack. However, it does not matter where a variable is declared in order to be able to access data on the heap. A heap is about allocating something additional elsewhere and having it hang around for as long as you want, being able to dispose of it whenever you want, and not having it tied to a particular variable.
Originally Posted by Blacky Ducky
For all practical purposes a variable that allows you to get to allocated heap memory will be a pointer, but in theory it could be a reference, or if type casting is involved it could be just about anything.
The question is somewhat like asking if your address must always be written on paper in order to be able to drive there.
You should learn more about pointers before learning what they can be used for.
Thanks guys , Appericiate your help.