Recall & Review
beginner
What is a structure in C++?
A structure in C++ is a user-defined data type that groups related variables of different types under one name. It helps organize data like a real-life object with multiple properties.
Click to reveal answer
beginner
How do you define a simple structure named
Person with name and age?You define it like this:<br>
struct Person {<br> std::string name;<br> int age;<br>};Click to reveal answer
beginner
How do you create a variable of a structure type and access its members?
First, declare a variable of the structure type, then use the dot
. operator to access members.<br>Example:<br>Person p;<br>p.name = "Alice";<br>p.age = 30;
Click to reveal answer
intermediate
Can structures in C++ have functions inside them?
Yes! Structures in C++ can have functions (called member functions) just like classes. This lets you group data and behavior together.
Click to reveal answer
intermediate
What is the difference between a structure and a class in C++?The main difference is default access:<br>- In a structure, members are public by default.<br>- In a class, members are private by default.<br>Otherwise, they are very similar.
Click to reveal answer
How do you define a structure in C++?
✗ Incorrect
Structures are defined using the
struct keyword followed by the name and member variables.What operator is used to access members of a structure variable?
✗ Incorrect
The dot operator is used to access members of a structure variable.
What is the default access level of members in a C++ structure?
✗ Incorrect
Members of a structure are public by default.
Can a structure in C++ contain functions?
✗ Incorrect
In C++, structures can have member functions just like classes.
Which of the following is a correct way to declare a structure variable?
✗ Incorrect
Both
Person p; and struct Person p; are valid in C++.Explain how to define a structure in C++ and create a variable of that structure.
Think about grouping related data under one name and how to use it.
You got /5 concepts.
Describe the differences and similarities between structures and classes in C++.
Focus on access and behavior.
You got /4 concepts.