A structure is a group of items in which each item can be refrenced with its own identifier and such item is called "member" of the structure. Aka record and field of the reord sometimes.
Matter-of-fact details:
- For declaring structures, there are 3 methods
- struct { //members }struct_varname;
- struct struct_tag {//members} ; struct struct_tag struct_varname;
- typedef struct {//members} TYPENAME; TYPENAME varname;
- the typedef declaration sometimes used to achieve the flavor of ADT specification within a C program.
- A member of structure may be declared to another structure. Eg: struct var1{ struct var2; struct var3; };
- ANSI standard C allows assignment of structures of the same type. But the original C developed by Kernighan and Ritchie doesnt allow this type of assignment but the field wise assignment.
- Two structures cannot be compared for equality in a single operation in C.
- Same identifier can be reused to name members of different structures. No ambiguity caused because while refrencing, the memeber name is followed by the structure name.
- Amount of memory specified by the structure is the sum of the storage specified by the members of the structure.
- There are boundary restrictions in some system. For eg: if there is a member of integer, it will start from memory location which is divisible by 4 (assuming integer occupies 4 bytes).
UNION:
C allows another type of structure, the union, which permits a variable to be interpreted in several different ways.
No comments:
Post a Comment