Structure and Union MCQs
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 55hard
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[3].y);
}Question 56hard
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
, {"hellos", "hi's", "hmm"}};
printf("%s", a[1][1]);
}Question 57hard
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 = {2};
printf("%d\n", u.p.x);
}Advertisement
Question 58hard
What will be the output of the following C code?
#include <stdio.h>
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}Question 59hard
What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p
printf("%s\n", ptrary[0]->name);
return 0;
}Question 60hard
What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p->name = "xyz";
p->next = NULL;
ptrary[0] = &p
printf("%s\n", p->name);
return 0;
}Advertisement
Question 61hard
In the following C code, we can access the 1st character of the string sval by using . . . . . .
#include <stdio.h>
struct
{
char *name;
union
{
char *sval;
} u;
} symtab[10];. .Question 62hard
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;
};
int main()
{
struct point p = {1};
struct notpoint p1 = p;
printf("%d\n", p1.x);
}Question 63hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m
s->c = "hello";
printf("%s", m.c);
}