home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / UNION1.C < prev    next >
Text File  |  1989-11-10  |  762b  |  38 lines

  1.                                          /* Chapter 11 - Program 5 */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. union {
  7.    int value;     /* This is the first part of the union */
  8.    struct {
  9.       char first;   /* These two values are the second     */
  10.       char second;
  11.    } half;
  12. } number;
  13.  
  14. long index;
  15.  
  16.    for (index = 12;index < 300000L;index += 35231L) {
  17.       number.value = index;
  18.       printf("%8x %6x %6x\n",number.value, number.half.first,
  19.               number.half.second);
  20.    }
  21. }
  22.  
  23.  
  24.  
  25. /* Result of execution
  26.  
  27.        c      c      0
  28.     89ab   ffab   ff89
  29.     134a     4a     13
  30.     9ce9   ffe9   ff9c
  31.     2688   ff88     26
  32.     b027     27   ffb0
  33.     39c6   ffc6     39
  34.     c365     65   ffc3
  35.     4d04      4     4d
  36.  
  37. */
  38.