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 11 of 27

Q101.
What is the output of this C code?
#include <stdio.h>
    int main()
    {
        struct p
        {
            char *name;
            struct p *next;
        };
        struct p *ptrary[10];
        struct p p, q;
        p.name = "xyz";
        p.next = NULL;
        ptrary[0] = &p;
        q.name = (char*)malloc(sizeof(char)*3);
        strcpy(q.name, p.name);
        q.next = &q;
        ptrary[1] = &q;
        printf("%s\n", ptrary[1]->next->next->name);
    }
Discuss
Answer: (d).xyz
Q102.
What is the output of this C code?
#include <stdio.h>
    typedef struct student
    {
        char *a;
    }stu;
    void main()
    {
        struct stu s;
        s.a = "hi";
        printf("%s", s.a);
    }
Discuss
Answer: (a).Compile time error
Q103.
What is the output of this C code?
#include <stdio.h>
    typedef struct student
    {
        char *a;
    }stu;
    void main()
    {
        struct student s;
        s.a = "hey";
        printf("%s", s.a);
    }
Discuss
Answer: (d).hey
Q104.
What is the output of this C code?
#include <stdio.h>
    typedef int integer;
    int main()
    {
        int i = 10, *ptr;
        float f = 20;
        integer j = i;
        ptr = &j;
        printf("%d\n", *ptr);
        return 0;
    }
Discuss
Answer: (d).10
Q105.
What is the output of this C code?
#include <stdio.h>
    int (*(x()))[2];
    typedef int (*(*ptr)())[2] ptrfoo;
    int main()
    {
        ptrfoo ptr1;
        ptr1 = x;
        ptr1();
        return 0;
    }
    int (*(x()))[2]
    {
        int (*ary)[2] = malloc(sizeof*ary);
        return &ary;
    }
Discuss
Answer: (a).Compile time error
Q106.
What is the output of this C code?
#include <stdio.h>
    int *(*(x()))[2];
    typedef int **(*ptrfoo)())[2];
    int main()
    {
        ptrfoo ptr1;
        ptr1 = x;
        ptr1();
        return 0;
    }
    int *(*(x()))[2]
    {
        int (*ary)[2] = malloc(sizeof * ary);
        return &ary;
    }
Discuss
Answer: (b).Nothing
Q107.
What is the output of this C code?
#include <stdio.h>
    typedef struct p
    {
        int x, y;
    };
    int main()
    {
        p k1 = {1, 2};
        printf("%d\n", k1.x);
    }
Discuss
Answer: (a).Compile time error
Q108.
What is the output of this C code?
#include <stdio.h>
    typedef struct p
    {
        int x, y;
    }k = {1, 2};
    int main()
    {
        p k1 = k;
        printf("%d\n", k1.x);
    }
Discuss
Answer: (a).Compile time error
Q109.
What is the output of this C code?
#include <stdio.h>
    typedef struct p
    {
        int x, y;
    }k;
    int main()
    {
        struct p p = {1, 2};
        k k1 = p;
        printf("%d\n", k1.x);
    }
Discuss
Answer: (b).1
Q110.
The correct syntax to use typedef for struct is
a) typedef struct temp
    {
        int a;
    }TEMP;

b) typedef struct
    {
        int a;
     }TEMP;

c) struct temp
    {
        int a;
    };
    typedef struct temp TEMP;

d) All of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (d).d

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!