Unions


  1. What type of data is holded by variable u int in the following C code?
    #include <stdio.h>
    union Example
    {
    int Nval;
    float Fval;
    char *Sval;
    } e;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Will be large enough to hold the largest of the three types;


  1. What will be the output of the following C code (Assuming size of int and float is 4)?
    #include <stdio.h>
    union
    {
    int Nval;
    float Fval;
    } U;
    void main()
    {
    printf("%d", sizeof(U));
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    4



  1. In the following C code, we can access the 1st character of the string sval by using _______.
    #include <stdio.h>
    struct
    {
    char *Name;
    union
    {
    char *Str;
    } u;
    } tab[15];











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Both tab[i].u.Str[0]. & *tab[i].u.Str


  1. Members of a union are accessed as________________.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    both union-pointer->member & union-name.member



  1. Which member of the union will be active after REF LINE in the following C code?
    #include <stdio.h>
    union test
    {
    int n;
    float fl;
    char ch;
    };
    union test t = {11,12.25,’N’}; //REF LINE











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    n