My Report

C Structure and Union Test – 2


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. Which of the following is not possible under any scenario?

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

    #include <stdio.h>
    struct temp
    {
        int a;
    } s;
    void func(struct temp s)
    {
        s.a = 10;
        printf("%d\t", s.a);
    }
    main()
    {
        func(s);
        printf("%d\t", s.a);
    } 

3. Which of the following return-type cannot be used for a function in C?

4. Presence of code like “s.t.b = 10” indicates __________

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

    #include <stdio.h>
    struct student
    {
        char *name;
    };
    void main()
    {
        struct student s, m;
        s.name = "st";
        m = s;
        printf("%s%s", s.name, m.name);
    } 

6. Which of the following operation is illegal in structures?

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

    #include <stdio.h>
    struct student
    {
        char *name;
    };
    struct student fun(void)
    {
        struct student s;
        s.name = "alan";
        return s;
    }
    void main()
    {
        struct student m = fun();
        s.name = "turing";
        printf("%s", m.name);
    } 

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

    #include <stdio.h>
    struct student
    {
        char *name;
    };
    struct student s;
    struct student fun(void)
    {
        s.name = "newton";
        printf("%s\n", s.name);
        s.name = "alan";
        return s;
    }
    void main()
    {
        struct student m = fun();
        printf("%s\n", m.name);
        m.name = "turing";
        printf("%s\n", s.name);
    }

 

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.