Re: A Query in "Pointers to Structures"



dbz wrote:
Hello everyone. I have a query. Lets say that following is given:-

struct struct1{
char *word;
int n;
} *p;


QUERIES:
What does the following refer to?

1) p->word
2) (*p)->n
3) (*p)->word
4) *(p->word)

Nothing yet. You have declared a structure and defined a pointer to it, but you don't have a structure yet.

p = malloc(sizeof *p);

Now, assuming success of malloc, p points to a structure and p[0] is the structure.

1. p->word is just fine.
2. p->n or (*p).n or p[0].n
3. (*p).word or p[0].word
4. *(p->word) is just fine.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
.



Relevant Pages