Save
...
Done [Finals]
Computer Programming 2
Struct
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Marc
Visit profile
Cards (19)
What is a struct in programming?
A
user-defined
data type
View source
What does a struct allow you to do?
Group multiple and different data types
View source
What are the variables in a struct called?
Members or fields
View source
What are the characteristics of a struct?
User-defined
: define multiple
members
Aggregates heterogeneous data
: stores different types
Value type
: copies all member data
Public members
: accessible to all
View source
How do you declare a struct in C++?
Use the
struct keyword followed by name
View source
What is the syntax to define a struct?
struct StructName { dataType memberName; };
View source
How do you initialize a struct variable?
Use the
struct name followed by variable name
View source
What is the output of cout << emp1.empName when emp1.empName is "Alice"?
Alice
View source
How can you modify a member of a struct?
By assigning a
new value
to it
View source
What is a nested struct?
A struct that is a
member of another struct
View source
What is the purpose of a nested struct?
Represents complex relationships
Organizes related data together
View source
How do you access a member of a nested struct?
Use the
outer struct's variable followed by inner
View source
What is the traditional initialization of a nested struct?
Using separate struct definitions
View source
How does C++11 improve struct initialization?
Allows initializer lists for
nested structs
View source
What is the C++20 version of struct initialization?
Uses designated initializers for members
View source
How can structs be used with functions?
Passed by value
Passed by reference
Can have
member functions
View source
What is the difference between pass by value and pass by reference?
Pass by value
copies data
, reference
does not
View source
Can a struct have member functions?
Yes, a struct can have member functions
View source
What are the uses of arrays in structs?
Store multiple values of the same type
Organize data within a struct
View source