Type Punning, part 3
In last session, we read struct
as a array
, now we will extend on this with two struct implementation.
Here is what it would look like:
Try it here.
Let's see how it works:
We have 2 structs,
Vector1
andVector2
.Vector1
contains 2 integers andVector2
constains 4 integers.It can be said,
Vector2
can be read as twoVector1
objects.In the example above, we are doing the same thing. We create a object of
Vector2
that store 4 integer variables and then read them as twoVector1
objects (as an array).Thus, we successfully read a
Vector2
data as twoVector1
data.
Last updated