I want to change member of structure under double pointer. Do you know how?
Example code
typedef struct {
int member;
} Ttype;
void changeMember(Ttype **foo) {
//I don`t know how to do it
//maybe
*foo->member = 1;
}
In the above example, n number of struct variables are created where n is entered by the user. To allocate the memory for n number of struct person , we used, ptr = (struct person*) malloc(n * sizeof(struct person)); Then, we used the ptr pointer to access elements of person .
As we know Pointer is a variable that stores the address of another variable of data types like int or float. Similarly, we can have a Pointer to Structures, In which the pointer variable point to the address of the user-defined data types i.e. Structures.
A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.
Initialization of the Structure Pointer We can also initialize a Structure Pointer directly during the declaration of a pointer. As we can see, a pointer ptr is pointing to the address structure_variable of the Structure.
Try
(*foo)->member = 1;
You need to explicitly use the * first. Otherwise it's an attempt to dereference member.
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