Hello and welcome and today the topic of discussion is NC programming will
understand what nested structure is all about. So prior to this we have discussed
everything about structures, everything about union that is what structure is all about, what is the memory allocation in a structure, how to access member of
structure, what is union, how to access element of union and then difference
between structure and union. So today in this video we will discuss about nested
structure. So let's start with nested structure. What nested structure is all
about? Nested structure is similar as nested loop. If you have ever make a
program of matrix so what you did you in nested or of a pattern then you
nested a loop inside a loop. So what nested loop is for i is equal to 0, i
less than 10, i plus plus and inside this loop I'm using one more loop for j is
equal to 0, j less than equal to suppose i or j plus plus. Here what am I doing is
that I am nesting a loop. So this is what nesting a loop. So in a similar fashion
when you are using a structure inside when you are using a structure inside
another structure then that is called nesting of structure. So let's read the
definition nested structure in C is nothing but structure within a structure
so like loop within a loop is nested loop structure within a structure is a
nested structure. One structure can be declared inside another structure very important. One structure can be declared inside another structure we as we
declare a structure member inside a structure. Let's start. So we have created a structure employee inside that I have two members one is ID one is name
ID is an integer type name is an character array. Now again we have
another member which is again a structure. So I have again a member so
this entire is a member third member this entire is a third member of my
structure one member was one member was what one member was ID one member was
name. Now the third member is itself a structure having name date there are
three members of this inner structure one is DD one is MM and one is YY that
is I'm declaring structure inside a structure inside a structure employee I'm declaring structure date having three variable fine. Now I have created a
variable DOJ. So what is DOJ? DOJ is a variable of which structure date and
what is E1? E1 is a variable of structure employee. Now let me make the
structure now let me make the memory structure now let me make the memory
structure of what what what I will make the memory structure of E1. So as I
have already told you many times so let me show you the memory structure let me
use some different color for you so the moment I'll make the memory structure of
E1 so what is E1? E1 is a object or a variable of what employee so I have
created how many member I have in employee three members one two and three
so one is ID so suppose I am reserving this space ID for this one is name so
one is name and name is an array of size 20 so this will be a array of size 20
and third is what date now date itself has what DOJ date itself has what DOJ
as a what DOJ so let me use some different color for it now so date
itself has let me use this so date itself has a another structure name as
DOJ which is divided into three part one is DD one is MM and one is Y Y Y Y fine
so this is the memory structure now now let's start to and now let's start so
E1 is representing this and DOJ is the inner part of that E1 fine so in main
what I did I am initializing ID E ID of E1 so I ID belongs to E1 ID of E1 with
101 so what will be there so let me use some different color for it let me use
this color so what will happen 101 will come here then we have E1 dot name E1
dot name as James so J a m e s James will come here then E1 dot DOG so I am
accessing DOG by E1 so what am I doing is not E1 dot DOG dot DD so this is the
method of accessing now dot DD is equal to 10 so what where I'll put 10 here E1
dot DOJ dot mm so inside this variable even there is a member variable DOJ and
inside that we have mm and I'm initializing with 11 and then E1 dot DOJ
Y Y 2014 so 2014 will come here fine so finally I have you know initialize the
entire memory of E1 fine now what am I doing is that I am printing the value of
employee ID so when when I will print the value of employee ID so this will
get printed like this and at the place of even dot ID what will be printed 101
so after that 101 will come employee dot name even dot name is James so James
will come and even dot joining date DD mm by way so like this it will come DD mm
and Y Y Y Y like this fine and now what you are printing even dot DOJ dot DD
what is that 10 so after that you will print 10 and at the place then 11 and
then 2014 so this is what nested structure is all about fine hope you
understood what memory is all about once you get this concept it will become very
easy for you to understand what nested structure is all about so at last I'll say what thank you so much for watching please like subscribe and share thank
you thank you so much thank you very much