Unions
A union shares memory between members. Only one is valid at a time.
Example
#include <stdio.h>
union V { int i; float f; };
int main(void) {
union V v;
v.i = 7;
printf("%d %zu\n", v.i, sizeof v);
return 0;
}Result
7 4
Exercise
Shared memory type.
V {}Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.