mcq on structures in C language,multiple choice questions on structure in C

Q5.What is the size of an empty structure in C?
a) 0
b) 1
c) 2
d) 4
Answer: a) 0


Q6.Which keyword is used to define a union in C?
a) union
b) typedef
c) struct
d) uniondef
Answer: a) union


Q7.What is the size of a union in C?
a) Sum of sizes of all members
b) Size of the largest member
c) Minimum size of all members
d) Size of the first member
Answer: b) Size of the largest member


Q8.How is a union variable declared in C?
b) union varname;
b) union varname = { };
c) union varname { };
d) union varname ();
Answer: a) union varname;


Q9.Can a union contain another union as a member in C?
a) Yes
b) No
Answer: b) No


Q10.What is the keyword used to access a member of a union variable in C?
a) .
b) ->
c) ::
d) >
Answer: a) .


Q11.What is the purpose of using structures in C programs?
a) To organize related data types together
b) To define functions with multiple return values
c) To declare global variables
d) To create constants
Answer: a) To organize related data types together


Q12.Can structures be passed as arguments to functions in C?
a) Yes
b) No
Answer: a) Yes


Q13.Which of the following is not a valid member of a structure variable?
a. Functions
b. Arrays
c. Pointers
d. Structures
Answer: a. Functions


Q14.When are structure members allocated memory in C?
a) Compile time
b) Run time
c) Link time
d) None of the above
Answer: b) Run time


Q15.Which operator is used to access members of a structure pointer in C?
a) .
b) ->
c) ::
d) >
Answer: b) ->


Q16.Which keyword is used to define an unnamed structure in C?
a)struct
b) typedef
c) union
d) structdef
Answer: a) struct


Q17.Can a structure have a member with the same name as the structure itself in C?
a) Yes
b) No
Answer: b) Yes


Q18.What is the purpose of using unions in C programs?
a) To organize related data types together
b) To define functions with multiple return values
c) To save memory
d) To create constants
Answer: c) To save memory


Q19.Can unions be passed as arguments to functions in C?
a) Yes
b) No
Answer: a) Yes


Q20.Which keyword is used to define a named union in C?
a) union
b) typedef
c) struct
d) uniondef
Answer: b) typedef


Q21.What is the output of the following C code snippet?
struct Student {
int rollno;
char name[20];
};
int main() {
sizeof(struct Student);
return 0;
}
a) 24
b) 20
c) 12
d) 16
Answer: a) 24


Q22.What is the output of the following C code snippet?
union Test {
int a;
char b;
};
int main() {
printf("%d", sizeof(union Test));
return 0;
}
a) 2
b) 4
c) 1
d) 8
Answer: b) 4


Q23.Which of the following statement is true about structures in C?
a) The size of a structure is always equal to the sum of the sizes of its members
b) A structure can have both static and dynamic members
c) A structure can contain pointers to other structures as members
d) A structure always stores its members in contiguous memory locations
Answer: c) A structure can contain pointers to other structures as members


Q24.What is the purpose of the typedef keyword when defining structures in C?
a) To alias the type of a structure
b) To declare a new type of structure
c) To prevent the definition of the structure from being modified
d) To declare a structure as a constant
Answer: a) To alias the type of a structure


Q25.In C, how are members of a structure accessed using a pointer to that structure?
a) ->
b) .
c) ::
d) >
Answer: a) ->


Q26.Which of the following is true about unions in C?
a) Unions are used to allocate memory for multiple members simultaneously
b) Unions can contain only one member at a time
c) Unions store members in contiguous memory locations
d) Unions have a fixed size based on the size of the first member
Answer: b) Unions can contain only one member at a time


Q27.What is the purpose of using structures or unions in C?
a) To improve the efficiency of programs
b) To organize related data types together
c) To reduce the complexity of code
d) To provide object-oriented programming features
Answer: b) To organize related data types together


Q28.How are structure members accessed using a structure variable in C?
a) ::
b) -
c) .
d) ->
Answer: c) .


Q29.Can structures or unions be nested within each other in C?
a) No, it is not allowed
b) Yes, but only structures can be nested
c) Yes, both structures and unions can be nested
d) Yes, but only unions can be nested
Answer: c) Yes, both structures and unions can be nested


Q30.What is the purpose of using pointers to structures or unions in C?
a) To access members efficiently
b) To store large amounts of data
c) To reduce the size of structures or unions
d) To pass structures or unions to functions
Answer: a) To access members efficiently



Previous Topic:-->>Function MCQ. || Next topic:-->>Pointer MCQ in C.