In a function, how to you assign this
a new value?
You can assign a value to a void pointer, but you must cast the variable to point to some specified type before you can dereference it. Pointer arithmetic is also not valid with void * pointers.
Declare a pointer variable with the same type as the normal variable. Initialize the pointer variable with the address of normal variable. Access the value of the variable by using asterisk (*) - it is known as dereference operator.
When you place an ampersand in front of a variable you will get it's address, this can be stored in a pointer vairable. When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.
You can assign 0 into a pointer: ptr = 0; The null pointer is the only integer literal that may be assigned to a pointer.
You can assign the object this
points at:
*this = XY;
But you can't assign the direct value of this
:
this = &XY; // Error: Expression is not assignable
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