Type Punning, part 2
In last session, we converted double
to int
, now we will extend on this with a struct implementation.
Here is what it would look like:
Try it here.
Let's see how it works:
We have a structs,
Vector
.Vector
contains 2 integersa
andb
.If we look at its memory allocation, it would be similar to an array with two int.
It means, we can read this struct as an array with indexes.
Hence, if we get pointer to
a
in struct, we can index on it to read value ofb
from its memory.
Last updated