Advertisements

Search results for union

Example:[1]

            What will be the output of the following program?
#include <stdio.h>
union mass
{
   	unsigned int a;
   	char b;
};
void main()
{
    union mass test;
    test.a = 0x00000001;
    printf("%d\n", test.b);
}
          
Option A:

            1
            
Option B:

            0
            
Option C:

            1 if machine is little endian, 0 if machine is big endian
            
Option D:

            Compile error
            
Correct Answer: option C
Example:[2]

            What will be the output of the following program if int takes 4 bytes and char takes 1 byte?
#include <stdio.h>
union mass
{
   	unsigned int a;
   	char b;
};
void main()
{
	union mass u;
    printf("%d\n", sizeof(u));
}
          
Option A:

            1
            
Option B:

            5
            
Option C:

            4
            
Option D:

            6
            
Correct Answer: option C

 Search Links


 Popular C search MCQs


 Popular C search examples