img
Question:
Published on: 28 March, 2024

What is a self referential structure? What is difference between Union & Structure?

Answer:

A structure may have a member whose is same as that of a structure itself. Such structures are called self-referential. Self-Referential Structure are one of the most useful features. They allow you to create data structures that contains references to data of the same type as themselves. Self-referential Structure is used in data structure such as binary tree, linked list, stack, Queue etc.

Example : Single linked list is implemented using following data structures

struct node {

        int value;

        struct node *next;

};

<pDifference between Structure and Union:

The difference between structure and union is,


1. The amount of memory required to store a structure variable is the sum of the size of all the members.
On the other hand, in case of unions, the amount of memory required is always equal to that required by its largest member.

2. In case of structure, each member have their own memory space but In union, one block is used by all the member of the union.

Random questions