How do you define a structure in C? a) struct name {type member1; type member2;} b) structure name {type member1; type member2;} c) struct name[] {type member1; type member2;} d) structure name() {type member1; type member2;}
What is the correct syntax to declare a structure variable? a) struct var_name; b) struct type var_name; c) type struct var_name; d) structure type var_name;
Which keyword is used to define a structure in C? a) struct b) structure c) type d) object
Accessing Structure Members
How do you access a structure member in C? a) . (dot operator) b) -> (arrow operator) c) [] (array index operator) d) Both a and b
What is the correct way to access a structure member through a pointer? a) ptr.member b) ptr->member c) ptr[member] d) ptr.member[]
What is the result of this code? struct Person { char name[30]; int age; }; struct Person p1 = {"Alice", 25}; printf("%s", p1.name); a) Prints “Alice” b) Prints “25” c) Prints the memory address of p1 d) Compilation error
Nested Structures
What is a nested structure? a) A structure that contains an array of elements b) A structure that contains another structure as a member c) A structure inside another structure of the same type d) A structure that has multiple members of the same type
How do you access a member of a nested structure? a) . (dot operator) b) -> (arrow operator) c) Both a and b d) [] (array index operator)
In which case can nested structures be useful? a) When defining structures with arrays as members b) When defining a structure to represent complex data that requires multiple levels c) For simple structures d) None of the above
Arrays of Structures
How do you declare an array of structures in C? a) struct Person arr[10]; b) struct Person[10] arr; c) Person arr[10]; d) struct[10] Person arr;
How do you access the elements of an array of structures? a) arr.member b) arr[i].member c) arr(i).member d) arr.member[i]
What happens when you initialize an array of structures? a) All members are initialized to zero by default b) Each structure element must be initialized explicitly c) Only the first element is initialized d) None of the above
Structure Pointers
How do you declare a pointer to a structure? a) struct Person *ptr; b) struct *ptr; c) ptr->Person; d) ptr: Person*;
What is the correct way to access a structure member through a pointer? a) ptr->member b) ptr.member c) ptr[member] d) *ptr.member
Which of the following is the correct syntax for using a structure pointer? a) struct Person *ptr = &p1; ptr->age = 30; b) struct *ptr = p1; ptr->age = 30; c) ptr = p1; ptr->age = 30; d) ptr->age = 30;
In the statement ptr->name = "Alice";, what does ptr represent? a) A structure variable b) A structure pointer c) A regular variable d) A pointer to a character array
Unions and Differences with Structures
What is the main difference between a structure and a union in C? a) A structure stores values of all its members simultaneously, while a union stores only one member at a time b) A structure stores only one value, while a union stores all values c) Both structures and unions store values in the same way d) Unions are used for storing arrays, while structures are used for variables
How do you declare a union? a) union name { type member1; type member2; }; b) union name { type member1, member2; }; c) structure name { type member1; }; d) union name[] { type member1; };
In a union, what happens when a new member is assigned a value? a) All members of the union are assigned the same value b) Only the member assigned the value holds it; other members are overwritten c) All members retain their values d) The program throws an error
How do you access a union member in C? a) Using the . (dot) operator b) Using the -> (arrow) operator c) Using array indexing d) Both a and b
When using a union, how much memory does it take? a) The memory size of the largest member b) The memory size of all members c) The size of the smallest member d) None of the above
What is the correct syntax for accessing a union member? a) union_name.member b) union_name->member c) member.union_name d) member[union_name]
Enumerations (enum)
What is an enumeration in C? a) A way to define a variable that can hold multiple values b) A user-defined data type that consists of a set of named integer constants c) A variable of type float d) A structure of named integer constants
How do you define an enumeration in C? a) enum name { value1, value2, value3 }; b) enum name { value1, value2 }; c) enum name(value1, value2); d) enum { value1, value2 };
What is the default value of the first item in an enumeration? a) 1 b) 0 c) -1 d) Undefined
How can you assign custom values to the members of an enumeration? a) enum name { value1 = 10, value2 = 20 }; b) enum name { 10 = value1, 20 = value2 }; c) enum name { value1, value2 = 20 }; d) enum name { 10, 20 = value2 };
How do you access an enumeration value? a) enum_name.value b) value.enum_name c) enum.value d) enum_name[value]
Which of the following is true about enumerations in C? a) The values of enumeration constants are automatically assigned b) Enumerations cannot store string values c) Enumeration values cannot be explicitly assigned d) All of the above
What is the default data type for enumeration values in C? a) float b) char c) int d) double
What will be the value of day in this code?
num days { Monday = 1, Tuesday, Wednesday }; enum days day = Wednesday;
a) 0 b) 1 c) 2 d) 3
Additional MCQs
Can a structure have members of different data types? a) Yes b) No c) Only integer and character types d) Only floating-point types
How many bytes of memory does a structure take? a) The size of the largest member b) The sum of the sizes of all members c) Depends on the data types of members d) The size of the first member
Which of the following is true about union members? a) All members occupy separate memory locations b) All members of the union share the same memory location c) Unions cannot have members of the same data type d) None of the above
Which of the following is not allowed in structures? a) Arrays as members b) Pointers as members c) Functions as members d) Structures as members
Which of the following will output “Yellow”?
enum color { Red = 1, Green = 2, Yellow = 3 }; printf("%d", Yellow);
a) 1 b) 2 c) 3 d) Compilation error
What happens when two structures share the same name in different scopes? a) They are treated as the same structure b) They are treated as different structures c) Compilation error d) One structure is ignored
Which of the following is true about pointers to structures? a) Structure pointers can be declared like any other pointer b) Structure pointers can only point to variables of the same structure type c) Structure pointers cannot be dereferenced d) None of the above
What is the size of the following structure?
struct MyStruct { int x; char y; };
a) 4 bytes b) 5 bytes c) 8 bytes d) 6 bytes
What will be printed by this code?
union Data { int i; float f; }; union Data data; data.i = 10; printf("%f", data.f);
a) 10 b) Undefined value c) 0 d) Compilation error
Which of the following is true about enumerations? a) An enumeration is automatically an integer type b) Enumeration constants are of type enum c) You can assign non-integer values to enumerations d) Enumerations cannot be used in switch cases
What happens when you print a structure directly using printf? a) It outputs all members of the structure b) It prints a memory address c) It causes a compilation error d) It prints the first member only
Which is the correct syntax for initializing a structure? a) struct Person p1 = {"Alice", 25}; b) struct Person p1; p1.name = "Alice"; p1.age = 25; c) p1 = {"Alice", 25}; d) Both a and b
Can a union hold different data types at the same time? a) Yes b) No c) Only strings and integers d) Only primitive types
Which of the following is the correct syntax for creating an array of unions? a) union Data arr[10]; b) union arr[10]; c) union Data[] arr; d) arr[union Data];
What is the memory size of a union if the members are: int x; char y; float z; a) 4 bytes b) 8 bytes c) 12 bytes d) 10 bytes
Which of the following types can be used as members in an enumeration? a) int b) float c) char d) All of the above
Can an enumeration value be assigned to a non-integer variable? a) Yes b) No c) Only char types d) Only float types
Which of the following is true for structures in C? a) Structure members can be of any data type b) Structures always occupy contiguous memory locations c) Structures cannot be nested d) Structures can only contain integer data types
What is a characteristic of a union in C? a) It can hold only one value at a time b) It uses memory for all its members c) Each member has its own memory location d) None of the above
How can an enumeration value be compared? a) Using == operator b) Using = operator c) Using != operator d) Both a and c
Qno
Answer
1
a) struct name {type member1; type member2;}
2
b) struct type var_name
3
a) struct
4
d) Both a and b
5
b) ptr->member
6
a) Prints “Alice”
7
b) A structure that contains another structure as a member
8
c) Both a and b
9
b) When defining a structure to represent complex data that requires multiple levels
10
a) struct Person arr[10];
11
b) arr[i].member
12
a) All members are initialized to zero by default
13
a) struct Person *ptr;
14
a) ptr->member
15
a) struct Person *ptr = &p1; ptr->age = 30;
16
b) A structure pointer
17
a) A structure stores values of all its members simultaneously, while a union stores only one member at a time
18
a) union name { type member1; type member2; };
19
b) Only the member assigned the value holds it; other members are overwritten
20
a) Using the . (dot) operator
21
a) The memory size of the largest member
22
a) union_name.member
23
b) A user-defined data type that consists of a set of named integer constants
24
a) enum name { value1, value2, value3 };
25
b) 0
26
a) enum name { value1 = 10, value2 = 20 };
27
a) enum_name.value
28
b) Enumerations cannot store string values
29
c) int
30
c) 2
31
a) Yes
32
b) The sum of the sizes of all members
33
b) All members of the union share the same memory location
34
c) Functions as members
35
c) 3
36
b) They are treated as different structures
37
a) Structure pointers can be declared like any other pointer
38
c) 8 bytes
39
b) Undefined value
40
a) An enumeration is automatically an integer type