My Report

C Structure and Union Test – 1


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?

    #include <stdio.h>
    void main()
    {
        struct student
        {
            int no;
            char name[20];
        };
        struct student s;
        no = 8;
        printf("%d", no);
    } 

2. How many bytes in memory taken by the following C structure?

    #include <stdio.h>
    struct test
    {
        int k;
        char c;
    }; 

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

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

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

    #include <stdio.h>
    struct
    {
        int k;
        char c;
    };
    int main()
    {
        struct p;
        p.k = 10;
        printf("%d\n", p.k);
    } 

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

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

6. What will be the output of the following C code according to C99 standard?

 
    #include <stdio.h>
    struct p
    {
        int k;
        char c;
        float f;
    };
    int main()
    {
        struct p x = {.c = 97, .k = 1, 3};
        printf("%f \n", x.f);
    }

7. What will be the output of the following C code according to C99 standard?

    #include <stdio.h>
    struct p
    {
        int k;
        char c;
        float f;
    };
    int main()
    {
        struct p x = {.c = 97};
        printf("%f\n", x.f);
    } 

8. What will be the output of the following C code according to C99 standard?

    #include <stdio.h>
    struct p
    {
        int k;
        char c;
        float f;
    };
    int main()
    {
        struct p x = {.c = 97, .f = 3, .k = 1};
        printf("%f\n", x.f);
    } 

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

    #include <stdio.h>
    struct
    {
        int k;
        char c;
    } p;
    int p = 10;
    int main()
    {
        p.k = 10;
        printf("%d %d\n", p.k, p);
    } 

 

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.