Q.1 Which keyword is used to define a structure in C?
struct
structure
record
class
Explanation - In C, the keyword 'struct' is used to define a structure.
Correct answer is: struct
Q.2 Which of the following allows grouping variables of different data types under a single name?
Array
Pointer
Structure
Macro
Explanation - A structure in C groups different data types under one name.
Correct answer is: Structure
Q.3 What is the default access specifier for members of a structure in C?
private
protected
public
none
Explanation - By default, members of a structure in C are public.
Correct answer is: public
Q.4 Which keyword is used to define a union in C?
struct
union
combine
group
Explanation - The 'union' keyword is used in C to define unions.
Correct answer is: union
Q.5 What differentiates a union from a structure?
Union stores only one member at a time
Union uses less memory
Union has private members
Union cannot be defined
Explanation - In unions, all members share the same memory space; only one member can hold a value at a time.
Correct answer is: Union stores only one member at a time
Q.6 What is the size of a structure in C?
Sum of all members' sizes
Size of largest member
Implementation dependent
None
Explanation - A structure allocates memory equal to the sum of its members, possibly with padding.
Correct answer is: Sum of all members' sizes
Q.7 What is the size of a union in C?
Sum of all members' sizes
Size of the smallest member
Size of the largest member
Always 4 bytes
Explanation - A union’s size is determined by its largest member, since all members share the same memory.
Correct answer is: Size of the largest member
Q.8 Which operator is used to access structure members?
. (dot)
-> (arrow)
:: (scope resolution)
& (ampersand)
Explanation - The dot operator is used with structure variables to access members directly.
Correct answer is: . (dot)
Q.9 Which operator is used to access members of a structure through a pointer?
. (dot)
-> (arrow)
:: (scope resolution)
* (asterisk)
Explanation - The arrow operator (->) is used to access structure members via pointers.
Correct answer is: -> (arrow)
Q.10 Can a structure in C contain another structure as a member?
Yes
No
Only if it's a union
Only in C++
Explanation - Structures in C can be nested by including another structure as a member.
Correct answer is: Yes
Q.11 Can a union contain a structure as a member?
Yes
No
Only in C++
Only with typedef
Explanation - A union can contain structures, as long as memory allows.
Correct answer is: Yes
Q.12 What will happen if we assign values to two different union members consecutively?
Both retain values
Last assignment overwrites previous
Compiler error
Undefined behavior
Explanation - Since union members share memory, the last assigned value overwrites the previous one.
Correct answer is: Last assignment overwrites previous
Q.13 Which of these is true about structures?
Structures cannot be passed to functions
Structures can be passed by value
Structures cannot be assigned
Structures are identical to classes
Explanation - In C, entire structures can be passed to functions by value.
Correct answer is: Structures can be passed by value
Q.14 Which of these can have typedef defined for them?
Only structures
Only unions
Both structures and unions
Neither
Explanation - Typedef can be used to create aliases for both structures and unions.
Correct answer is: Both structures and unions
Q.15 What is structure padding?
Extra memory used for alignment
Extra space in stack
Error in structure size
Removing unused bytes
Explanation - Structure padding aligns members in memory for faster access, increasing size.
Correct answer is: Extra memory used for alignment
Q.16 Can structures have pointers to themselves as members?
Yes
No
Only in unions
Only in C++
Explanation - Self-referential structures can have pointers to their own type (commonly used in linked lists).
Correct answer is: Yes
Q.17 Which statement about unions is correct?
All members can be used simultaneously
Unions save memory
Union members are private by default
Unions cannot contain arrays
Explanation - Unions share memory among members, thus being memory efficient.
Correct answer is: Unions save memory
Q.18 What is the output size of struct {char a; int b;}?
5 bytes
8 bytes
4 bytes
Depends on compiler
Explanation - Due to padding, size depends on compiler and architecture.
Correct answer is: Depends on compiler
Q.19 Which C feature is best suited to represent a student record containing roll number, name, and marks?
Array
Pointer
Structure
Union
Explanation - Structures allow grouping different data types like int, char[], and float.
Correct answer is: Structure
Q.20 Which C feature is best suited when you need to use different data types but only one at a time?
Array
Pointer
Structure
Union
Explanation - Unions are useful when only one type of data is required at a time, saving memory.
Correct answer is: Union
Q.21 What happens if no memory alignment is required in structures?
Padding increases
Padding decreases
No padding
Undefined behavior
Explanation - If no alignment requirement exists, padding is unnecessary and size is minimized.
Correct answer is: No padding
Q.22 Which among these is false for structures?
Structures can have arrays
Structures can be nested
Structures cannot have functions
Structures can be passed by value
Explanation - In C, structures cannot contain functions directly (unlike in C++).
Correct answer is: Structures cannot have functions
Q.23 Which storage class can a structure variable have?
auto, static, extern
Only auto
Only static
Only extern
Explanation - Structure variables can use any standard storage class in C.
Correct answer is: auto, static, extern
Q.24 Can we declare an array of structures in C?
Yes
No
Only if static
Only if global
Explanation - Arrays of structures are valid and commonly used in programs.
Correct answer is: Yes
Q.25 Which is more memory efficient if only one member is used at a time?
Structure
Union
Array
Pointer
Explanation - Unions save memory since all members share the same location.
Correct answer is: Union
