Structure and Union MCQs

190 questionsC-ProgramPage 16 of 22

Practice free Structure and Union multiple-choice questions with instant answer feedback and step-by-step solutions. Click an option to check yourself, reveal the full explanation, and work through all 190 questions — no login required.

Question 136hard
What will be the output of the following C code?
#include <stdio.h>
struct p
{
    unsigned int x : 2;
    unsigned int y : 2;
};
int main()
{
    struct p p;
    p.x = 3;
    p.y = 4;
    printf("%d\n", p.y);
}
Question 137hard
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    printf("%d", lookup[3]);
}
Question 138hard
What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
    int x, y;
}k = {1, 2};
int main()
{
    p k1 = k;
    printf("%d\n", k1.x);
}
Advertisement
Question 139hard
What will be the output of the following 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);
}
Question 140easy
Which of the following is not allowed?
Question 141easy
User-defined data type can be derived by . . . . . . . .
Advertisement
Question 142hard
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");
}
Question 143easy
Which of the following are themselves a collection of different data types?
Question 144hard
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);
}