Thread: why the result of print statement for a.x isn''t 1?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    40

    why the result of print statement for a.x isn''t 1?

    why the result of print statement for a.x isn''t 1?

    Code:
    #include<stdio.h>
    
    union u{ int x; char y;}a;
    int main ()
    {
        a.x = 1;
        a.y = 'A';  
        printf ("%d ", a.x);
        printf ("%c ", a.y);
        
        printf ("\n %d ", sizeof(a.x));
        printf ("\n %d ", sizeof(a.y));
        return 0;
    }
    result

    65 A
    4
    1

    65 A
    4
    1
    Last edited by skyr6546; 04-03-2020 at 09:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does this statement print a 0?
    By lilywest in forum C Programming
    Replies: 3
    Last Post: 11-22-2013, 10:29 AM
  2. Problem with print out the result
    By pp00 in forum C Programming
    Replies: 11
    Last Post: 11-14-2012, 01:56 AM
  3. Print statement won't print
    By Sakari in forum C Programming
    Replies: 17
    Last Post: 06-20-2012, 06:41 PM
  4. Use result in a new statement
    By SilentPirate007 in forum C Programming
    Replies: 8
    Last Post: 02-16-2010, 08:31 AM
  5. Why i can get the result print to the screen
    By wise_ron in forum C Programming
    Replies: 7
    Last Post: 05-22-2006, 08:06 PM

Tags for this Thread