home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_01.ZIP / UNISTRUC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-22  |  876 b   |  30 lines

  1. /*UNISTRUC.C - From page 317 of "Microsoft C Programming for    */
  2. /* IBM" by Robert Lafore. It demonstrates union of structures.  */
  3. /* This file has same problem as UNION.C on this disk and is    */
  4. /* described in it's source file description located at the     */
  5. /* top of the source just like this description.                */
  6. /****************************************************************/
  7.  
  8. main()
  9. {
  10. struct twoints {
  11.    int intnum1;
  12.    int intnum2;
  13. } stex;
  14.  
  15. union intflo {
  16.    struct twoints stex;
  17.    float fltnum;
  18. } unex;
  19.  
  20.    printf("sizeof(union intflo) = %d\n", sizeof(union intflo));
  21.    unex.stex.intnum1 = 734;
  22.    unex.stex.intnum2 = -333;
  23.    printf("unex.stex.intnum1 = %d\n", unex.stex.intnum1);
  24.    printf("unex.stex.intnum2 = %d\n", unex.stex.intnum2);
  25.    unex.fltnum = 867.43;
  26.    printf("unex.fltnum = %f\n", unex.fltnum);
  27. }
  28.  
  29.  
  30.