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 154easy
Which is the correct syntax to use typedef for struct?
Question 155hard
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;
};
struct point foo();
int main()
{
struct point p = {1};
struct notpoint p1 = {2, 3};
p1 = foo();
printf("%d\n", p1.x);
}
struct point foo()
{
struct point temp = {1, 2};
return temp;
}Question 156hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s[2], r[2];
s[1] = s[0] = "alan";
printf("%s%s", s[0].name, s[1].name);
}Advertisement
Question 157hard
What will be the output of the following C code?
#include <stdio.h>
int main()
{
struct p
{
char *name;
struct p *next;
};
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p
strcpy(q.name, p.name);
ptrary[1] = &q
printf("%s\n", ptrary[1]->name);
return 0;
}Question 158hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char a[5];
};
void main()
{
struct student s[] = {"hi", "hey"};
printf("%c", s[0].a[1]);
}Question 159hard
What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8)
#include <stdio.h>
union utemp
{
int a;
double b;
char c;
}u;
int main()
{
u.c = 'A';
u.a = 1;
printf("%d", sizeof(u));
}Advertisement
Question 160hard
What will be the output of the following C code?
#include <stdio.h>
union
{
int x;
char y;
}p;
int main()
{
p.x = 10;
printf("%d\n", sizeof(p));
}Question 161easy
Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?
(Assume: struct temp{int a;}s;)Question 162hard
What will be the output of the following C code?
#include <stdio.h>
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}