Would these two assignments be equivalent, i.e. perfom exactly the same thing?
*pointer = object
pointer = &object
, where pointer is a pointer to an "object-instance".
Or does this only make sense for primitive types.
No, these are not the same.
pointer = &object sets pointer so that it points at object.
*pointer = object sets the value of thing being pointed to by pointer to be equal to the value of object.
Absolutely not.
*pointer = object
changes the memory the pointer points to.
pointer = &object
changes the pointer.
pointer ----> object1
&object ----> object
In the first case, this becomes:
pointer ----> object
&object ----> object
In the second case:
----> object1 //could turn into a memory leak
&object, pointer ----> object
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