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?
A. String
B. Structures
C. Char
D. None of the above
View Answer
Ans : B
Explanation: A structure is a user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
2. Which operator connects the structure name to its member name?
A. -
B. ->
C. .
D. both . and ->
View Answer
Ans : C
Explanation: None
3. Which of the following cannot be a structure member?
A. Function
B. Array
C. Structure
D. None of the above
View Answer
Ans : A
Explanation: None.
4. What is the correct syntax to declare a function foo() which receives an array of structure in function?
A. void foo(struct *var);
B. void foo(struct *var[]);
C. void foo(struct var);
D. none of the mentioned
View Answer
Ans : A
Explanation: None
5. Union differs from structure in the following way
A. All members are used at a time
B. Only one member can be used at a time
C. Union cannot have more members
D. Union initialized all members as structure
View Answer
Ans : B
Explanation: When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of sizes of its members. The smaller members may end with unused slack bytes. While in case of Union when a variable is associated with a union, the compiler allocates the memory by considering the size of the largest memory. So, size of union is equal to the size of largest member.
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];
};
A. 8 byte
B. 4 byte
C. 10 byte
D. 18 byte
View Answer
Ans : C
Explanation: Largest size among the three structure variable is selected that is char z[10].
7. Members of a union are accessed as________________.
A. union-name.member
B. union-pointer->member
C. Both a & b
D. None of the mentioned
View Answer
Ans : C
Explanation: None
8. It is not possible to create an array of pointer to structures.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: Making sure of the length has nothing to do with whether you assign or copy. You cannot assign to an array in C, ever. The language doesn't allow it.
9. Which of the following statement is True?
A. User has to explicitly define the numeric value of enumerations
B. User has a control over the size of enumeration variables.
C. Enumeration can have an effect local to the block, if desired
D. Enumerations have a global effect throughout the file.
View Answer
Ans : C
Explanation: User has a control over the size of enumeration variable
10. size of union is size of the longest element in the union
A. Yes
B. No
C. May Be
D. Can't Say
View Answer
Ans : A
Explanation: Max size of the union is the size of the largest data type or the memory taken by largest member.
Also check :
Discussion