so now we’re going to learn about strux
so now we’re going to learn about strux and a struct is a data structure that’s
and a struct is a data structure that’s
and a struct is a data structure that’s where we get the name struct data
where we get the name struct data
where we get the name struct data structure a struct is a data structure
structure a struct is a data structure
structure a struct is a data structure which allows us to compose together
which allows us to compose together
which allows us to compose together values of different types so it’s an
values of different types so it’s an
values of different types so it’s an aggregate data type we could also say
aggregate data type we could also say
aggregate data type we could also say it’s an aggregate data type it
it’s an aggregate data type it
it’s an aggregate data type it aggregates together values of a
aggregates together values of a
aggregates together values of a different type so let me just show you
different type so let me just show you
different type so let me just show you how that works and then we’ll revisit
how that works and then we’ll revisit
how that works and then we’ll revisit this definition it’ll make a little bit
this definition it’ll make a little bit
this definition it’ll make a little bit more sense so we just go type and then
more sense so we just go type and then
more sense so we just go type and then we give it a name we just create a name
we give it a name we just create a name
we give it a name we just create a name and identifier and the underlying type
and identifier and the underlying type
and identifier and the underlying type is struct and then we do curly braces
is struct and then we do curly braces
is struct and then we do curly braces and we’re just going to put some fields
and we’re just going to put some fields
and we’re just going to put some fields in here first is going to be a string
in here first is going to be a string
in here first is going to be a string last is going to be a string and then I
last is going to be a string and then I
last is going to be a string and then I think that’s good first and last and
think that’s good first and last and
think that’s good first and last and then we can come down here we can create
then we can come down here we can create
then we can come down here we can create values of that type this is a
values of that type this is a
values of that type this is a user-defined type the type is person the
user-defined type the type is person the
user-defined type the type is person the underlying type is struct so now we’re
underlying type is struct so now we’re
underlying type is struct so now we’re gonna create values of that type and so
gonna create values of that type and so
gonna create values of that type and so to use a composite literal we’re gonna
to use a composite literal we’re gonna
to use a composite literal we’re gonna use the type and then curly braces and
use the type and then curly braces and
use the type and then curly braces and so person 1 is going to be you know
so person 1 is going to be you know
so person 1 is going to be you know their first name will be James and then
their first name will be James and then
their first name will be James and then their last name will be bond and then we
their last name will be bond and then we
their last name will be bond and then we could do person to well I guess let’s
could do person to well I guess let’s
could do person to well I guess let’s type it out P to colon equals person the
type it out P to colon equals person the
type it out P to colon equals person the type and then the curly brace is for a
type and then the curly brace is for a
type and then the curly brace is for a composite that rolled their first name
composite that rolled their first name
composite that rolled their first name is Miss and their last name is
is Miss and their last name is
is Miss and their last name is Moneypenny and you have to have that
Moneypenny and you have to have that
Moneypenny and you have to have that trailing comma there and that is the
trailing comma there and that is the
trailing comma there and that is the preferred method for creating a value of
preferred method for creating a value of
preferred method for creating a value of type person a value where the underlying
type person a value where the underlying
type person a value where the underlying type is a struct you you initialize each
type is a struct you you initialize each
type is a struct you you initialize each field on its own line so now I could
field on its own line so now I could
field on its own line so now I could print those out value p1 value p2 and if
print those out value p1 value p2 and if
print those out value p1 value p2 and if I run that I’m gonna see I’ve created
I run that I’m gonna see I’ve created
I run that I’m gonna see I’ve created values of type person and they have
values of type person and they have
values of type person and they have fields in there I could even access
fields in there I could even access
fields in there I could even access those with dot notation so I could do p1
those with dot notation so I could do p1
those with dot notation so I could do p1 dot first p1 dot last and p2 dot first
dot first p1 dot last and p2 dot first
dot first p1 dot last and p2 dot first and p2
and p2
and p2 and I can access those fields with dot
and I can access those fields with dot
and I can access those fields with dot notation so that looks a lot like an
notation so that looks a lot like an
notation so that looks a lot like an object to you or a class or we created
object to you or a class or we created
object to you or a class or we created something and then we created instances
something and then we created instances
something and then we created instances of it this is that’s that’s a good
of it this is that’s that’s a good
of it this is that’s that’s a good approximation I don’t want to use those
approximation I don’t want to use those
approximation I don’t want to use those words we don’t use those words and go we
words we don’t use those words and go we
words we don’t use those words and go we don’t say object we don’t say class we
don’t say object we don’t say class we
don’t say object we don’t say class we say we’ve created a value of type right
say we’ve created a value of type right
say we’ve created a value of type right so this is a type person and now we’ve
so this is a type person and now we’ve
so this is a type person and now we’ve created a value of type person so here
created a value of type person so here
created a value of type person so here we created the value of type person and
we created the value of type person and
we created the value of type person and we assigned it to the variable p1 so you
we assigned it to the variable p1 so you
we assigned it to the variable p1 so you create values of a certain type so
create values of a certain type so
create values of a certain type so that’s the first introduction to
that’s the first introduction to
that’s the first introduction to creating a struct and that’s how structs
creating a struct and that’s how structs
creating a struct and that’s how structs are used and they could a lot they allow
are used and they could a lot they allow
are used and they could a lot they allow you to aggregate together values of
you to aggregate together values of
you to aggregate together values of different types so we put in different
different types so we put in different
different types so we put in different values in here write different fields
values in here write different fields
values in here write different fields different types we could do age if we
different types we could do age if we
different types we could do age if we want it so I could come up here and do
want it so I could come up here and do
want it so I could come up here and do age hint and I could come down here and
age hint and I could come down here and
age hint and I could come down here and I could do age and add in I don’t know
I could do age and add in I don’t know
I could do age and add in I don’t know 32 and I could do age here and add in 27
32 and I could do age here and add in 27
32 and I could do age here and add in 27 and then I could print out their age as
and then I could print out their age as
and then I could print out their age as if I wanted so it’s putting together a
if I wanted so it’s putting together a
if I wanted so it’s putting together a grenading together composing together
grenading together composing together
grenading together composing together composing together values of different
composing together values of different
composing together values of different types that’s what a struct allows us to
types that’s what a struct allows us to
types that’s what a struct allows us to do create a data structure with values
do create a data structure with values
do create a data structure with values of a different type so these are these
of a different type so these are these
of a different type so these are these are this is known as a composite data
are this is known as a composite data
are this is known as a composite data structure we’re composing together
structure we’re composing together
structure we’re composing together values of a different type it can also
values of a different type it can also
values of a different type it can also be referred to as an aggregate data
be referred to as an aggregate data
be referred to as an aggregate data structure or a complex data structure
structure or a complex data structure
structure or a complex data structure and so I have all of that right here a
and so I have all of that right here a
and so I have all of that right here a struct is a composite data type
struct is a composite data type
struct is a composite data type composite data types AKA aggregate data
composite data types AKA aggregate data
composite data types AKA aggregate data types
types
types also known as is AKA and AKA complex
also known as is AKA and AKA complex
also known as is AKA and AKA complex data types structs allow us to compose
data types structs allow us to compose
data types structs allow us to compose together values of a different type so
together values of a different type so
together values of a different type so that’s your first step to understanding
that’s your first step to understanding
that’s your first step to understanding Struck’s
Struck’s
Struck’s [Music]
Be First to Comment