0
39kviews
What are the uses of structure? Explain with an example. Also explain concept of nested Structures.
1 Answer
1
6.1kviews

A structure is a collection of variables of same or different datatypes. It is useful in storing or using informations or databases.

Example: An employee’s record must show its salary, position, experience, etc. It all can be stored in one single variable using structures.

struct Employee
   {
char ename[20];
int id;
float salary,experience;
   };

Structure written inside another structure is called as nesting of two structures. Nested Structures are allowed in C Programming Language. We can write one Structure inside another structure as member of another structure.

Example:

struct date
{
int date;
int month;
int year; 
};

struct Employee
   {
char ename[20];
int ssn;
float salary;
struct date doj;
};

Here, struct date is passed as a member of struct employee. Hence, nested.

Please log in to add an answer.