Hey All,
sorry for the late reply, Uni problem sets got the best of my week.
Helios: I meant (*(*ipp)). ipp is on the stack but from what I now know, I would have to guess **ipp would be on the heap since it would be ipp pointing to a heap pointer. (Thanks Repeater for the great clarification)
keskiverto:
The pointer foo is a pointer on the stack, pointing to an unnamed pointer on the heap.
bar is an integer on the stack that holds the object 7.
*foo is a pointer on the heap and it is now pointing to the variable bar that is on the stack.
**foo points to a pointer on the heap and gives this pointer the object 42? Usually we use the Ampersand to give variables objects but perhaps that is different for heap memory.
General questions:
1. I have seen a lot of code where a pointer points to an int in the heap:
int *ipp = new int;
But what is exactly the variable in the heap? Is there a possible way to give the heap memory a variable name such as we do within the stack? Example:
1 2
|
int x = 5;
int *p =&x;
|
I can now either change the value of x with x =7 or with *p =7. Is the only way to do so with heap objects is to use pointers?
2. When we create a pointer on the stack, we use: int *p = &x; Meaning, with the Ampersand. But on the heap we just use int *p = new int; Meaning, we only use "new". I'm beginning to think that since we don't use Ampersands for the heap memory, it is a given that we have to use pointers to interact with objects on the heap.
3.
int **ipp = new int*;
ipp is a pointer to an unnamed pointer. How can we actually use the unnamed pointer if it is (excuse the redundancy) unnamed?
---------------------------
I'm looking forward to your responses. Again thank you Repeater, helios, keskiverto, and Peter87 for the clarifications and input.