Structure and Union MCQs

190 questionsC-ProgramPage 6 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 46hard
What will be the output of the following 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);
}
Question 47hard
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *a[3] = {"hello", "this"};
    printf("%s", a[1]);
}
Question 48hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
struct student fun(void)
{
    struct student s;
    s.name = "alan";
    return s;
}
void main()
{
    struct student m = fun();
    printf("%s", m.name);
}
Advertisement
Question 49easy
What is the correct syntax to declare a function foo() which receives an array of structure in function?
Question 50hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *c;
};
void main()
{
    struct student *s;
    s->c = "hello";
    printf("%s", s->c);
}
Question 51hard
What will be the output of the following C code?
#include <stdio.h>
struct p
{
    int x[2];
};
struct q
{
    int *x;
};
int main()
{
    struct p p1 = {1, 2};
    struct q *ptr1;
    ptr1->x = (struct q*)&p1.x
    printf("%d\n", ptr1->x[1]);
}
Advertisement
Question 52hard
What will be the output of the following C code?
#include <stdio.h>
union p
{
    int x;
    char y;
}k = {.y = 97};
int main()
{
    printf("%d\n", k.y);
}
Question 53hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
void main()
{
    struct student s, m;
    s.name = "st";
    m = s;
    printf("%s%s", s.name, m.name);
}
Question 54hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
struct student s[2], r[2];
void main()
{
    s[0].name = "alan";
    s[1] = s[0];
    r = s;
    printf("%s%s", r[0].name, r[1].name);
}