I am trying to write a C program. I need the address of variable "recq". Can someone pls help me figure that out?
typedef struct {
int recq;
} dd;
struct test {
dd a;
};
main(){
struct test *mm;
mm=(struct test *) malloc (sizeof (struct test));
ss=&(mm->a.recq);
printf("%p",ss);
}
Accessing structure's member through pointer. A structure's member can be accesssed through pointer in two ways: Referencing pointer to another address to access memory. Using dynamic memory allocation.
It is defined as the pointer which points to the address of the memory block that stores a structure is known as the structure pointer. 1. To access members of a structure using pointers, we use the ( -> ) operator. 2. The using asterisk ( * ) and dot ( . ) operator with the structure pointer
Here, ptr is a pointer to struct. To access members of a structure using pointers, we use the -> operator. In this example, the address of person1 is stored in the personPtr pointer using personPtr = &person1;. Now, you can access the members of person1 using the personPtr pointer.
Similarly, we can have a pointer to structures, where a pointer variable can point to the address of a structure variable. Here is how we can declare a pointer to a structure variable.
What you have looks good except you need to declare the ss variable:
int *ss;
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