



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Pointer to Structures
struct Person {
char name[30]; //30 bytes int age; //4 bytes float length; //4 bytes
};
struct Person abc, *ptr;
ptr = &abc;
ptr = ptr + 1; // skips 38 bytes
How to Access Members of a
Structures
Member of a structure is accessed using member
structure.
Member Access Operator
member access operator
Indirect Member Access (Arrow)
Operator
Members of a structure can also be accessed using
pointer to structures with ( -> ) operator.
Member Access Operators
member access operator.
ptr -> age
is equivalent to
(* ptr).age
Nested Structures
Struct Person
{
char name[30]; //30 bytes int age; //4 bytes float length; //4 bytes
};
struct Student
{
struct Person p; //38 bytes int rollno; //4 bytes
};
Un-named Nested Structures
struct Person { char name[30]; //30 bytes int age; //4 bytes float length; //4 bytes };
struct Student { struct { char name[30]; int age; float length; }p; int rollno; //4 bytes };
Union
Unions allows a same portion of memory to be accessed as different data types. Its declaration and use is similar to that of structures but its functionality is totally different.
union model_name { type1 element1 ; type2 element2 ; type3 element3 ; ... } object_name ;
All the elements of the union declaration occupy the same space of memory. Its size is equal to the greatest element of the declaration.
Union
union Person { char name[30]; //30 bytes int age; float length; };
union Person abc, * ptr;
ptr = &abc;
ptr = ptr + 1; //skips 30 bytes
Little Endian and Big Endian
typedef
typedef existing_type new_type_name ;
typedef
Example:
// character