Structure and Union MCQs

190 questionsC-ProgramPage 5 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 37hard
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    typedef struct p *q;
    struct p
    {
        int x;
        char y;
        q ptr;
    };
    struct p p = {1, 2, &p};
    printf("%d\n", p.ptr->x);
    return 0;
}
Question 38hard
Can the following C code be compiled successfully?
#include <stdio.h>
struct p
{
    int k;
    char c;
    float f;
};
int main()
{
    struct p x = {.c = 97, .f = 3, .k = 1};
    printf("%f\n", x.f);
}
Question 39hard
What will be the output of the following 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
}
Advertisement
Question 40easy
Which of the following share a similarity in syntax?
1. Union, 2. Structure, 3. Arrays and 4. Pointers
Question 41hard
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    struct student
    {
        int no;
        char name[20];
    };
    struct student s;
    no = 8;
    printf("%d", no);
}
Question 42hard
What will be the output of the following 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);
}
Advertisement
Question 43hard
What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
int main()
{
    struct point p = {1};
    struct point p1 = {1};
    if(p == p1)
        printf("equal\n");
    else
        printf("not equal\n");
}
Question 44medium
Which of the following structure declaration doesn't require pass-by-reference?
Question 45medium
How many bytes in memory taken by the following C structure?
#include <stdio.h>
struct test
{
    int k;
    char c;
};