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\n", data.resource);
  17. printf("Index: %d\n", data.index);
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0.01s 5284KB
stdin
10
aba
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
stdout
Index: 1
Resource: 5.000000
Index: 0