in Programming in C
466 views
1 vote
1 vote
What is the output of the program?

                int main()
                {
                    union a
                    {
                        int i;
                        char ch[2];
                    };
                    union a u;
                    u.ch[0] = 3;
                    u.ch[1] = 2;
                    printf("%d, %d, %d", u.ch[0], u.ch[1], u.i);
                    return 0;
                }

 

in Programming in C
by
466 views

3 Answers

0 votes
0 votes
3 ,2 , garbage value

3 Comments

3, 2, garbage value
0
0
can you explain why garbage value is printed??????
0
0
because its not initialized
0
0
0 votes
0 votes

answer is 3 2 515

because c processor follows little endian (in little endian mystery lower bytes are being stored at lower address and upper bytes are being stored at higher addresses)

https://www.geeksforgeeks.org/little-and-big-endian-mystery/

 

 

0 votes
0 votes
3 2 515

Bcz char take one byte and int take 4 byte .

Memory represation is lower byte store first

0000 0000 0000 0000 0000 0010 0000 0011=515

Related questions