0% found this document useful (0 votes)
15 views8 pages

Day 8

This document discusses different types of C structures: 1. Array of structures allows storing multiple structures of the same type in an array. For example, an array of employee structures can store details of multiple employees. 2. Structures can contain array members to store multiple values of the same type like marks of different subjects. 3. Nested structures allow a structure to contain another structure as a member. For example, an employee structure can contain a date of birth structure. 4. Self-referential structures contain a pointer to their own structure type as a member, allowing linked structures like linked lists.

Uploaded by

khitcsec3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Day 8

This document discusses different types of C structures: 1. Array of structures allows storing multiple structures of the same type in an array. For example, an array of employee structures can store details of multiple employees. 2. Structures can contain array members to store multiple values of the same type like marks of different subjects. 3. Nested structures allow a structure to contain another structure as a member. For example, an employee structure can contain a date of birth structure. 4. Self-referential structures contain a pointer to their own structure type as a member, allowing linked structures like linked lists.

Uploaded by

khitcsec3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DAY – 8

BASICS OF C
What will you learn?
 Array of Structures
 Arrays within Structures
 Nested Structure
 Self – Referential Structure
ARRAY OF STRUCUTRES
It is collection of structures those of same type. In other words elements of
an array are structures. If we are required to deal with 5 employees’ details, we
would declare an array of struct employee of size 5 as follows.

struct employee

int empno;

char name[20];

float salary;

}
A structure array is declared as follows:

struct employee e[5];


MEMORY REPRESENTATION
Empno name salary

e[0]  2 bytes   20 bytes   4 bytes 

e[1]  2 bytes   20 bytes   4 bytes 

e[2]  2 bytes   20 bytes   4 bytes 

e[3]  2 bytes   20 bytes   4 bytes 

e[4]  2 bytes   20 bytes   4 bytes 


ARRAYS WITHIN STRUCTURES
C permits the use of array as structure member. We can use single or
multi-dimensional array of type int or float.

struct marks
{
int sub[3];
int total;
};
struct marks student;

In the above structure, the member sub contains three elements such as sub[0],
sub[1] and sub[2].These elements can be accessed by using the subscripts. For
example [Link][2], indicates the marks obtained by student and third
subject.
NESTED STRUCTURES
 A Structure can be placed within another structure.

 This means a structure contains another structure as its member.

 A structure that contains another structure as its member is called nested


structure.

A structure can be nested as follows:


struct date struct employee
{ {
int day; int empno;
int month; char name[20];
int year; float salary;
}; struct date dob;
};
SELF REFERENTIAL STRUCTURES
Self Referential Structure is a structure that contains a pointer
to a structure of the same type as that of the structure, as its member.

Eg:
struct node
{
int value;
struct node *next;
};

Here the structure contains two data items, one is the value, and the
other is next which is pointer to the structure of type node.

You might also like