Output of the Program

0

 

union test{
int a;
struct stu
{
char a1;
char a2;
char a3;
char a4;
}s1;
};
main()

{
union test p;
p.a = 1024;
printf(“%d,%d,%d,%d”,p.s1.a1,p.s1.a2,p.s1.a3,p.s1.a4);
}

(A)256,0,0,0

(B)0,256,0,0

(C)0,4,0,0

(D)0,0,0,4

Ravi Garg edited question
    0
    Sonali Kapoor (anonymous)

    Explanation
    p.a = 1024
    (1024) binay = 00000000,00000000,00000100,00000000
    Saved in Memory Like this: 00000000,00000100,00000000,00000000
    When we try to access it from struct variable, then
    a1: read 1 Byte == 0
    a2: read 2 Btye == 4
    a3: read 2 Btye == 0
    a4: read 2 Btye == 0
    hence answer is (C)

    Sonali Kapoor answered
      Add image to editor add image from link

      Question stats

      • Active
      • Views215 times
      • Answers1 answer
      • Followers1 follower
      Question and answer is powered by AnsPress