Skip to content

Instantly share code, notes, and snippets.

@TheCodeEngine
Created April 24, 2013 13:03
Show Gist options
  • Save TheCodeEngine/5451966 to your computer and use it in GitHub Desktop.
Save TheCodeEngine/5451966 to your computer and use it in GitHub Desktop.
Union example
#include <stdio.h>
#include <stdlib.h>
/********************
Ausgabe:
Q1 Count: 4
Q2 Weight: 1.50
Q3 Volume: 2.000000
*********************/
int main(int argc, char const *argv[])
{
typedef union
{
short count;
float weight;
float volume;
} quantity;
quantity q1 = {4}; // means count
quantity q2 = {.weight=1.5};
quantity q3 = {.volume=2.0};
fprintf(stdout, "Q1 Count: %d\n", q1.count);
fprintf(stdout, "Q2 Weight: %.2f\n", q2.weight); // 2 nackommastellen
fprintf(stdout, "Q3 Volume: %f\n", q3.volume);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment