I have a structure:
struct mystruct { int* pointer; }; structure mystruct* struct_inst;
Now I want to change the value pointed to by struct_inst->pointer
. How can I do that?
EDIT
I didn't write it, but pointer
already points to an area of memory allocated with malloc
.
x is a pointer to a pointer to int. *x yields a int* (pointer to int ) **x = is like *(*x) = so you first obtain the pointer to int then by dereferencing you are able to set the value at the address.
Response:In Hi-Tech compiler if any pointer variable is modified during code execution, the compiler will give a warning "Dereferencing uninitialized pointer" if the pointer variable is not initialised with some address.To overcome this warning , initialize the pointer variable with any address during the pointer ...
Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers.
As with any pointer. To change the address it points to:
struct_inst->pointer = &var;
To change the value at the address to which it points:
*(struct_inst->pointer) = var;
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