adplus-dvertising

Welcome to the Structures and Unions MCQs Page

Dive deep into the fascinating world of Structures and Unions with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Structures and Unions, a crucial aspect of C Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Structures and Unions, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Structures and Unions. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Structures and Unions. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Structures and Unions MCQs | Page 7 of 27

Q61.
What is the output of this C code?
#include <stdio.h>
    struct p
     {
        int x;
        int y;
    };
    int main()
    {
        struct p p1[] = {1, 92, 3, 94, 5, 96};
        struct p *ptr1 = p1;
        int x = (sizeof(p1) / 5);
        if (x == 3)
            printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
        else
            printf("false\n");
    }
Discuss
Answer: (d).false
Q62.
What is the output of this C code?
#include <stdio.h>
    struct student
    {
        char *c;
    };
    void main()
    {
        struct student m;
        struct student *s = &m;
        s->c = "hello";
        printf("%s", s->c);
    }
Discuss
Answer: (a).hello
Q63.
What is the output of this C code?
#include <stdio.h>
    struct student
    {
        char *c;
    };
    void main()
    {
        struct student *s;
        s->c = "hello";
        printf("%s", s->c);
    }
Discuss
Answer: (b).Segmentation fault
Q64.
What is the output of this C code?
#include <stdio.h>
    struct student
    {
        char *c;
    };
    void main()
    {
        struct student m;
        struct student *s = &m;
        s->c = "hello";
        printf("%s", m.c);
    }
Discuss
Answer: (c).hello
Q65.
What is the output of this C code?
#include <stdio.h>
    struct student
    {
        char *c;
    };
    void main()
    {
        struct student m;
        struct student *s = &m;
        (*s).c = "hello";
        printf("%s", m.c);
    }
Discuss
Answer: (d).hello
Q66.
What is the output of this C code?
#include <stdio.h>
    struct student
    {
        char *c;
    };
    void main()
    {
        struct student n;
        struct student *s = &n;
        (*s).c = "hello";
        printf("%p\n%p\n", s, &n);
    }
Discuss
Answer: (d).Same address
Q67.
What is the output of this C code?
#include <stdio.h>
    struct p
    {
        int x[2];
    };
    struct q
    {
        int *x;
    };
    int main()
    {
        struct p p1 = {1, 2};
        struct q *ptr1;
        ptr1->x = (struct q*)&p1.x;
        printf("%d\n", ptr1->x[1]);
    }
Discuss
Answer: (b).Segmentation fault/code crash
Q68.
What is the output of this C code?
#include <stdio.h>
    struct p
    {
        int x[2];
    };
    struct q
    {
        int *x;
    };
    int main()
    {
        struct p p1 = {1, 2};
        struct q *ptr1 = (struct q*)&p1;
        ptr1->x = (struct q*)&p1.x;
        printf("%d\n", ptr1->x[0]);
    }
Discuss
Answer: (b).Undefined behaviour
Q69.
What is the output of this C code?
#include <stdio.h>
    struct p
    {
        int x;
        int y;
    };
    int main()
    {
        struct p p1[] = {1, 2, 3, 4, 5, 6};
        struct p *ptr1 = p1;
        printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
    }
Discuss
Answer: (a).1 5
Q70.
What is the output of this C code?
#include <stdio.h>
    struct p
    {
        int x;
        char y;
    };
    int main(){
        struct p p1[] = {1, 92, 3, 94, 5, 96};
        struct p *ptr1 = p1;
        int x = (sizeof(p1) / sizeof(struct p));
        printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
    }
Discuss
Answer: (d).1 5

Suggested Topics

Are you eager to expand your knowledge beyond C Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!