Vidyalelo
C Programming · all questions

Structure and Union
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

190

Questions

8/10

Page

Pick an option on a question to see the right answer and solution.

User-defined data type can be derived by . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    int no;
    char name[20];
};
void main()
{
    student s;
    s.no = 8;
    printf("hello");
}

Select an option to see the answer and solution.

Which of the following are themselves a collection of different data types?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
void foo(struct point*);
int main()
{
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
}
void foo(struct point p[])
{
    printf("%d %d\n", p->x, (p + 2).y);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
typedef struct student
{
    char *a;
}stu;
void main()
{
    struct student s;
    s.a = "hey";
    printf("%s", s.a);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    char x : 2;
    int y : 2;
};
int main()
{
    struct p p;
    p.x = 2;
    p.y = 1;
    p.x = p.x & p.y;
    printf("%d\n", p.x);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
typedef struct p *q;
int main()
{
    struct p
    {
        int x;
        char y;
        q ptr;
    };
    struct p p = {1, 2, &p};
    printf("%d\n", p.ptr->x);
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
union u
{
    struct
    {
        unsigned char x : 2;
        unsigned int y : 2;
    }p;
    int x;
};
int main()
{
    union u u.p.x = 2;
    printf("%d\n", u.p.x);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    unsigned int x : 7;
    unsigned int y : 2;
};
int main()
{
    struct p p;
    p.x = 110;
    p.y = 2;
    printf("%d\n", p.x);
}

Select an option to see the answer and solution.

Which of the following technique is faster for travelling in binary trees?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
void foo(struct point*);
int main()
{
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
}
void foo(struct point p[])
{
    printf("%d %d\n", p->x, (p + 2)->y);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char a[];
};
void main()
{
    struct student s;
    printf("%d", sizeof(struct student));
}

Select an option to see the answer and solution.

Which function is responsible for searching in the table? (For #define IN 1, the name IN and replacement text 1 are stored in a "table")

Select an option to see the answer and solution.

Which is the correct syntax to use typedef for struct?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
struct notpoint
{
    int x;
    int y;
};
struct point foo();
int main()
{
    struct point p = {1};
    struct notpoint p1 = {2, 3};
    p1 = foo();
    printf("%d\n", p1.x);
}
struct point foo()
{
    struct point temp = {1, 2};
    return temp;
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
void main()
{
    struct student s[2], r[2];
    s[1] = s[0] = "alan";
    printf("%s%s", s[0].name, s[1].name);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    struct p
    {
        char *name;
        struct p *next;
    };
    struct p p, q;
    p.name = "xyz";
    p.next = NULL;
    ptrary[0] = &p;
    strcpy(q.name, p.name);
    ptrary[1] = &q;
    printf("%s\n", ptrary[1]->name);
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char a[5];
};
void main()
{
    struct student s[] = {"hi", "hey"};
    printf("%c", s[0].a[1]);
}

Select an option to see the answer and solution.

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));
}

Select an option to see the answer and solution.

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));
}

Select an option to see the answer and solution.