C Programming Multiple Choice Question - Structure And Union
This section focuses on the "Structure And Union" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following are themselves a collection of different data types?
View Answer
2. Which operator connects the structure name to its member name?
View Answer
3. Which of the following cannot be a structure member?
View Answer
4. What is the correct syntax to declare a function foo() which receives an array of structure in function?
View Answer
5. Union differs from structure in the following way
View Answer
6. The size of the following union, where an int occupies 4 bytes of memory is
union demo
{
float x;
int y;
char z[10];
};
View Answer
7. Members of a union are accessed as________________.
View Answer
8. It is not possible to create an array of pointer to structures.
View Answer
9. Which of the following statement is True?
View Answer
10. size of union is size of the longest element in the union
View Answer
11. What is the similarity between a structure, union and enumeration?
View Answer
12. Which of the following share a similarity in syntax?
1. Union 2. Structure 3. Arrays 4. Pointers
View Answer
13. Size of a union is determined by size of the.
View Answer
14. Which operator connects the structure name to its member name?
View Answer
15. How will you free the allocated memory ?
View Answer
16. Which of the following accesses a variable in structure b?
View Answer
17. Which of the following accesses a variable in structure *b?
View Answer
18. Which of the following is a properly defined struct?
View Answer
19. Which properly declares a variable of struct foo?
View Answer
20. What is the output of this program?
#include <stdio.h>
struct test {
int x = 0;
char y = 'A';
};
int main()
{
struct test t;
printf("%d, %c", s.x, s.y);
return 0;
}
View Answer
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
31. What is the output of this program?
#include <stdio.h>
struct employee
{
char *empname;
int salary;
};
int main()
{
struct employee e, e1;
e.empname = "Sridhar";
e1 = e;
printf("%s %s", e.empname, e1.empname);
return 0;
}
View Answer
32. What is the output of this program?
#include <stdio.h>
struct student
{
int no = 5;
char name[20];
};
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
View Answer
33. What is the output of this program?
#include <stdio.h>
void main()
{
struct number
{
int no;
char name[20];
};
struct number s;
s.no = 50;
printf("%d", s.no);
}
View Answer
34. Number of bytes in memory taken by the below structure is
#include <stdio.h>
struct test
{
int k;
char c;
};
View Answer
35. What is the output of this program?
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
View Answer
36. Which of the following are incorrect syntax for pointer to structure?
(Assuming struct temp{int b;}*my_struct;)
View Answer
37. 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;)
View Answer
38. For the following function call which option is not possible?
func(&s.a); //where s is a variable of type struct and a is the member of the struct.
View Answer
39. The correct syntax to access the member of the ith structure in the array of structures is?
Assuming:
struct temp
{
int b;
}s[50];
View Answer
40. The number of distinct nodes the following struct declaration can point to is
struct node
{
struct node *left;
struct node *centre;
struct node *right;
};
View Answer
Also check :
Discussion