Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a nested structure.
C
struct Point {
int x;
int y;
};
struct Rectangle {
struct Point [1];
struct Point bottomRight;
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like 'point' instead of a descriptive one.
Forgetting to name the nested struct member.
✗ Incorrect
The nested structure member is named 'topLeft' to represent the top-left corner point of the rectangle.
2fill in blank
mediumComplete the code to access the x coordinate of the topLeft point in a Rectangle variable.
C
struct Rectangle rect;
int x_coord = rect.[1].x; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Accessing bottomRight instead of topLeft.
Trying to access x directly from rect without the nested member.
✗ Incorrect
To access the x coordinate of the topLeft point, use rect.topLeft.x.
3fill in blank
hardFix the error in the code to correctly initialize a nested structure.
C
struct Rectangle rect = { { [1], 10 }, {20, 30} }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the member name instead of a value.
Using braces incorrectly around a single integer.
✗ Incorrect
The nested Point is initialized with two integers. The first integer is 5 for x coordinate.
4fill in blank
hardFill both blanks to declare and initialize a nested structure variable.
C
struct Rectangle [1] = { {10, [2], {20, 30} };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid variable name.
Confusing the y coordinate value.
✗ Incorrect
The variable name is 'rect' and the y coordinate of topLeft is 15.
5fill in blank
hardFill all three blanks to define a nested structure and assign values.
C
struct Point {
int [1];
int [2];
};
struct Rectangle {
struct Point topLeft;
struct Point [3];
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect member names for Point.
Naming the second Point member incorrectly.
✗ Incorrect
The Point struct has members 'x' and 'y'. The Rectangle has a second Point named 'bottomRight'.