In C language when a structure is referring or pointing to the structure of the same type, then it is called ‘self referential structure’.
Example of a structure-
Example of a self referential structure-
Here, *link is a pointer to the structure of type ‘manu’. Hence, it is a self referential structure.
Uses of Self Referential Structure:
Self referential structures are used in order to build some other complex data structures.
-
Linked List
-
Stack
-
Queue
-
Tree
-
Graph
Types of Self Referential Structure:
1. Self Referential Structure With Single Link:
These types of self referential structures can have only one pointer that refers to or pointing to the same structure.
Example:
Hence output of the above example will be ’20’.
2. Self Referential Structure With Multiple Link:
These types of self referential structures can have more than one pointer that refers to or pointing to the same structure.
Example:
Hence output of the above example will be ’20 10‘.
Be First to Comment