Recall & Review
beginner
What is an array of structures in C?
An array of structures is a collection where each element is a structure. It lets you store multiple records of the same type together, like a list of students where each student has a name and age.
Click to reveal answer
beginner
How do you declare an array of structures in C?
First, define a structure type using
struct. Then declare an array of that structure type, for example: <br>struct Student { char name[20]; int age; } students[10]; creates an array of 10 students.Click to reveal answer
beginner
How do you access members of a structure inside an array?
Use the array index and dot operator. For example,
students[0].age accesses the age of the first student. This is like picking a book from a shelf and then reading its title.Click to reveal answer
intermediate
Can you initialize an array of structures at declaration?
Yes, you can initialize it with values like this: <br>
struct Student students[2] = { {"Alice", 20}, {"Bob", 22} }; This sets the first student's name and age, and the second student's too.Click to reveal answer
intermediate
Why use an array of structures instead of separate arrays?
Using an array of structures keeps related data together, making code easier to read and less error-prone. For example, storing names and ages in one array of structures is clearer than two separate arrays for names and ages.
Click to reveal answer
How do you declare an array of 5 structures named 'Book' in C?
✗ Incorrect
The correct syntax is
struct Book books[5]; where 'Book' is the structure type and 'books' is the array name.How do you access the 'price' member of the third element in an array 'items' of structures?
✗ Incorrect
Array indexing starts at 0, so the third element is at index 2. Use
items[2].price to access it.Which operator is used to access a member of a structure in an array?
✗ Incorrect
Use the dot operator
. to access members of a structure when you have the structure variable itself.Can you initialize an array of structures at the time of declaration in C?
✗ Incorrect
You can initialize an array of structures using curly braces with values for each element.
What is a benefit of using an array of structures?
✗ Incorrect
An array of structures groups related data together, making it easier to manage and understand.
Explain how to declare and use an array of structures in C with an example.
Think about a list of students with name and age.
You got /4 concepts.
Describe the advantages of using an array of structures over separate arrays for related data.
Imagine storing names and ages separately vs together.
You got /4 concepts.