Using Typedef With Structures
Introduction :
- It allows us to introduce synonyms for data types which could have been declared some other way.
- It is used to give new name for the structure.
- New name is used for Creating instances,passing values to function,declaration etc...
Explain ?typedef int XYZ; XYZ age; XYZ roll;
- New name given for integer is XYZ.
- 'XYZ' and 'int' are now synonyms.
- 'age' is of type XYZ i.e of integer type.
Example 1 :
Example 2 :typedef struct { char ename[30]; int ssn; int deptno; }employee;
What we have done ?typedef struct Rec { char ename[30]; int ssn; int deptno; }employee;
- Consider Example 2, Rec is tag-name.
- 'employee' is nothing but new data type.
- We can now create the variables of type 'employee'
- Tag name is optional .
Live Example :
typedef struct b1 { char bname[30]; int ssn; int pages; }book; book b1,b2,b3;


0 comments
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email