Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pointer to member of struct [closed]

Tags:

c

pointers

struct

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);    

}      
like image 718
Pkp Avatar asked May 05 '11 06:05

Pkp


People also ask

How do you access a structure's member through pointer?

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.

What is structure pointer in C++?

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

How to access members of a struct using-> operator?

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.

Can We have a pointer to a structure variable?

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.


1 Answers

What you have looks good except you need to declare the ss variable:

int *ss;
like image 166
Robert Groves Avatar answered Sep 29 '22 00:09

Robert Groves