fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. union Data {
  5. uint8_t index; // 1 byte
  6. float resource; // 4 bytes
  7. };
  8.  
  9. int main() {
  10. union Data data;
  11.  
  12. data.index = 1;
  13. printf("Index: %d\n", data.index);
  14.  
  15. data.resource = 5.0;
  16. printf("Resource: %f, %d\n", data.resource, data.index);
  17. printf("Index: %d\n", data.index);
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Index: 1
Resource: 5.000000, 0
Index: 0