Structure and Union MCQs

190 questionsC-ProgramPage 17 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 145hard
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);
}
Question 146hard
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);
}
Question 147hard
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;
}
Advertisement
Question 148hard
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);
}
Question 149hard
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);
}
Question 150easy
Which of the following technique is faster for travelling in binary trees?
Advertisement
Question 151hard
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);
}
Question 152hard
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));
}
Question 153easy
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")