jeudi 19 mars 2015

Regarding typedefing structs


Please go easy on me as I'm walking a thin line here. I really searched the existing threads and I could only see statements with no examples and it just went over my head. I have been thinking whether or not to ask this for two days because I'm frankly scared to ask a silly question here. But I think I'll take the risk now and hope you go easy on me as this is my first question.


Those existent threads suggested that typedefing struct will save repeating codes, but how? Any example please? I have the following for instance:



struct Node {
int data;
Node* value;
};


To create a new node, I would say:



Node n1;


Even if I typedef the struct like:



typedef struct Node {
int data;
Node* value;
} type;


To create a new node, I would do:



type n2;


I don't really see much difference. Please provide some example that really showcases the usefulness of typedef on structs.




Aucun commentaire:

Enregistrer un commentaire