0
0
Cprogramming~5 mins

Array of structures - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aarray struct Book books[5];
BBook struct books[5];
Cstruct books Book[5];
Dstruct Book books[5];
How do you access the 'price' member of the third element in an array 'items' of structures?
Aitems[2].price
Bitems.price[3]
Citems[3].price
Ditems->price[3]
Which operator is used to access a member of a structure in an array?
A* (asterisk)
B-> (arrow)
C. (dot)
D& (ampersand)
Can you initialize an array of structures at the time of declaration in C?
ANo, initialization must be done later.
BYes, using curly braces with values.
COnly for arrays of integers.
DOnly if the array size is 1.
What is a benefit of using an array of structures?
AIt groups related data together for easier management.
BIt avoids using structures.
CIt makes the program run faster always.
DIt separates related data into different arrays.
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.