447 views
1 votes
1 votes
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;
                }

 

3 Answers

0 votes
0 votes
3 ,2 , garbage value
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

0 votes
0 votes
0 answers
1
Mayankprakash asked Jul 15, 2018
209 views
My doubt is very basic, I want to understand what is the use of signed and unsigned used with integer.?2.what does size of signed int (-128 to 127) signify?3how to big en...
3 votes
3 votes
1 answer
3
arpit.bagri asked Jul 26, 2023
640 views
What is the output of the code given below? #include <stdio.h #include <string.h union sample { int i; float f; char c; double d; char str[20]; }; int main() { // union s...