MCQ - Structure And Union in C Programming
21. What is the output of this program?
#include <stdio.h>
struct test {
int x;
char y;
} test;
int main()
{
test.x = 10;
test.y = 'A';
printf("%d %c", test.x,test.y);
return 0;
}
View Answer
22. What is the output of this program?
#include <stdio.h>
struct result{
char sub[20];
int marks;
};
void main()
{
struct result res[] = { {"Maths",100},
{"Science",90},
{"English",85}
};
printf("%s ", res[1].sub);
printf("%d", (*(res+2)).marks);
}
View Answer
23. What will be the size of the following structure?
struct demo{
int a;
char b;
float c;
}
View Answer
24. What is the output of this program?
#include <stdio.h>
void main()
{
struct demo{
char * a;
int n;
};
struct demo p = {"hello", 2015};
struct demo q = p;
printf("%d", printf("%s",q.a));
}
View Answer
25. What is the output of this program?
#include <stdio.h>
int main()
{
union demo {
int x;
int y;
};
union demo a = 100;
printf("%d %d",a.x,a.y);
}
View Answer
26. What is the output of this program?
#include <stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=4, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d", MON, TUE, WED, THU, FRI, SAT);
return 0;
}
View Answer
27. What is the output of this program?
#include <stdio.h>
int main(){
struct simp
{
int i = 6;
char city[] = "chennai";
};
struct simp s1;
printf("%d",s1.city);
printf("%d", s1.i);
return 0;
}
View Answer
28. What is the output of this program?
#include <stdio.h>
struct
{
int i;
float ft;
}decl;
int main(){
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}
View Answer
29. What is the output of this program?
void main()
{
struct bitfields {
int bits_1: 2;
int bits_2: 9;
int bits_3: 6;
int bits_4: 1;
}bit;
printf("%d", sizeof(bit));
}
View Answer
30. What is the output of this program?
#include <stdio.h>
int main(){
struct leader
{
char *lead;
int born;
};
struct leader l1 = {"AbdulKalam", 1931};
struct leader l2 = l1;
printf("%s %d", l2.lead, l1.born);
}
View Answer
Also check :