My Report

C Structure and Union Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8)

    #include <stdio.h>
    union utemp
    {
        int a;
        double b;
        char c;
    }u;
    int main()
    {
        u.c = 'A';
        u.a = 1;
        printf("%d", sizeof(u));
    }

2. What will be the output of the following C code?

    #include <stdio.h>
    union
    {
        int x;
        char y;
    }p;
    int main()
    {
        p.y = 60;
        printf("%d\n", sizeof(p));
    } 

3. Which of the following share a similarity in syntax?

1. Union, 2. Structure, 3. Arrays and 4. Pointers

4. What will be the output of the following C code?

    #include <stdio.h>
    union p
    {
        int x;
        float y;
    };
    int main()
    {
        union p p, b;
        p.x = 10;
        printf("%f\n", p.y);
    } 

5. What will be the output of the following C code?

    #include <stdio.h>
    union p
    {
        int x;
        char y;
    }k = {1, 97};
    int main()
    {
        printf("%d\n", k.y);
    } 

6. What will be the output of the following C code?

    #include <stdio.h>
    union
    {
        int x;
        char y;
    }p;
    int main()
    {
        p.x = 10;
        printf("%d\n", sizeof(p));
    } 

7. What will be the output of the following C code?

    #include <stdio.h>
    union p
    {
        int x;
        char y;
    }k = {.y = 97};
    int main()
    {
        printf("%d\n", k.y);
    } 

8. What will be the output of the following C code?

    #include <stdio.h>
    union p
    {
        int x;
        char y;
    };
    int main()
    {
        union p p, b;
        p.y = 60;
        b.x = 12;
        printf("%d\n", p.y);
    } 

 

Start practicing “1000 MCQs on C”, and once you are ready, you can take tests on all topics by attempting our “C Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.