Possible Duplicate:
What are the barriers to understanding pointers and what can be done to overcome them?
i am really not familiar to c and pointers, I want to understand what is going on here :
typedef struct {
int q[QUEUESIZE+1];
int first;
int last;
int count;
} queue;
init_queue(queue *q)
{
q->first = 0;
q->last = QUEUESIZE-1;
q->count = 0;
}
Is that correct to think that : q->first = 0 implies that if one assign to the ‘0’ address some value ‘val’, then *(q->first) will return ‘val’ ?
q->firstis a short hand for(*q).firstThe parenthesis are necessary because
.would be evaluated before thedereference *and sinceqis a pointer wellq.first == NOT A VALID THINGqueue aQ;init_queue(&aQ);
the function
init_queuetake a pointer to aqueuenot a pointer to anint.The role of this function is to
initializeall the field of the structure to be usable by other function at a latter time.