/* */ Click to Join Live Class with Shankar sir Call 9798158723

C Union MCQ


Q1. The size of a union is determined by the size of the __________
  1. First member in the union
  2. Last member in the union
  3. Biggest member in the union
  4. Sum of the sizes of all members

Answer:- (C).
Explanations :none.
Q2. Which member of the union will be active after REF LINE in the following C code?
      #include 
    union temp
    {
        int a;
        float b;
        char c;
    };
    union temp s = {1,2.5,’A’}; //REF LINE
  
  1. a
  2. b
  3. c
  4. Such declaration are illegal

Answer:- (A).
Explanations :none.
Q3. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1)
     #include 
    union uTemp
    {
        double a;
        int b[10];
        char c;
    }u;
 
  1. 4
  2. 8
  3. 40
  4. 80

Answer:- (A).
Explanations :none.
Q4. What type of data is holded by variable u int in the following C code?
    #include 
    union u_tag
    {
        int ival;
        float fval;
        char *sval;
    } u;
  1. Will be large enough to hold the largest of the three types;
  2. Will be large enough to hold the smallest of the three types;
  3. Will be large enough to hold the all of the three types;
  4. None of the mentioned

Answer:- (A).
Explanations :none.
Q5. Members of a union are accessed as________________
  1. union-name.member
  2. union-pointer->member
  3. both union-name.member & union-pointer->member
  4. none of the mentioned

Answer:- (C).
Explanations :none
Q6. In the following C code, we can access the 1st character of the string sval by using _______
  #include 
    struct
    {
        char *name;
        union
        {
            char *sval;
        } u;
    } symtab[10];
  1. *symtab[i].u.sval
  2. symtab[i].u.sval[0].
  3. You cannot have union inside structure
  4. Both *symtab[i].u.sval & symtab[i].u.sval[0].

Answer:- (D).
Explanations :none
Q7. What will be the output of the following C code (Assuming size of int and float is 4)?
   #include 
    union
    {
        int ival;
        float fval;
    } u;
    void main()
    {
        printf("%d", sizeof(u));
    }
	
  1. 16
  2. 8
  3. 8
  4. 32

Answer:- (C).
Explanations :none.
Q8. What will be the output of the following C code?
    #include 
    union stu
    {
        int ival;
        float fval;
    };
    void main()
    {
        union stu r;
        r.ival = 5;
        printf("%d", r.ival);
    }
  1. 9
  2. Compile time error
  3. 16
  4. 5

Answer:- (D).
Explanations :none.
Q9. What will be the output of the following C code?
#include 
    union
    {
        int x;
        char y;
    }p;
    int main()
    {
        p.x = 10;
        printf("%d\n", sizeof(p));
    }
  1. Compile time error
  2. sizeof(int) + sizeof(char)
  3. Depends on the compiler
  4. sizeof(int)

Answer:- (D).
Explanations :none.
Q10. What will be the output of the following C code?
#include 
    union
    {
        int x;
        char y;
    }p;
    int main()
    {
        p.y = 60;
        printf("%d\n", sizeof(p));
    }
}
  1. Compile time error
  2. sizeof(int) + sizeof(char)
  3. Depends on the compiler
  4. sizeof(char)

Answer:- (C).
Explanations :none.