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
.
You are creating a pointer of type mystruct, I think perhaps you didn't want a pointer:
Of if you need a mystruct pointer on the heap instead:
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;