Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a nested structure inside another structure.
C++
struct Outer {
struct [1] {
int x;
} inner;
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the member variable name instead of the structure name.
Using lowercase for the structure name.
✗ Incorrect
The nested structure inside Outer is named 'Inner'.
2fill in blank
mediumComplete the code to access the member 'x' of the nested structure.
C++
Outer::Inner obj; obj.[1] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access a member that does not exist.
Confusing the nested structure name with its member.
✗ Incorrect
The member 'x' is defined inside the nested structure Inner.
3fill in blank
hardFix the error in the code to correctly initialize the nested structure member.
C++
struct Outer {
struct Inner {
int x;
} [1];
};
Outer o = {{{{10}}}}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the structure name instead of the member variable name.
Using a different variable name not declared.
✗ Incorrect
The member variable of type Inner is named 'inner', so it must be used in initialization.
4fill in blank
hardFill both blanks to define and initialize a nested structure with two members.
C++
struct Outer {
struct [1] {
int a;
int [2];
} inner;
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect member names.
Using different structure names.
✗ Incorrect
The nested structure is named 'Inner' and the second member is 'b'.
5fill in blank
hardFill all three blanks to create a nested structure and initialize its members.
C++
struct Outer {
struct [1] {
int [2];
int [3];
} inner;
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong member names or structure names.
Confusing member names with structure names.
✗ Incorrect
The nested structure is named 'Inner' with members 'a' and 'b'.