Cards (19)

  • What is a struct in programming?
    A user-defined data type
  • What does a struct allow you to do?
    Group multiple and different data types
  • What are the variables in a struct called?
    Members or fields
  • 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
  • How do you declare a struct in C++?
    Use the struct keyword followed by name
  • What is the syntax to define a struct?
    struct StructName { dataType memberName; };
  • How do you initialize a struct variable?
    Use the struct name followed by variable name
  • What is the output of cout << emp1.empName when emp1.empName is "Alice"?
    Alice
  • How can you modify a member of a struct?
    By assigning a new value to it
  • What is a nested struct?
    A struct that is a member of another struct
  • What is the purpose of a nested struct?
    • Represents complex relationships
    • Organizes related data together
  • How do you access a member of a nested struct?
    Use the outer struct's variable followed by inner
  • What is the traditional initialization of a nested struct?
    Using separate struct definitions
  • How does C++11 improve struct initialization?
    Allows initializer lists for nested structs
  • What is the C++20 version of struct initialization?
    Uses designated initializers for members
  • How can structs be used with functions?
    • Passed by value
    • Passed by reference
    • Can have member functions
  • What is the difference between pass by value and pass by reference?
    Pass by value copies data, reference does not
  • Can a struct have member functions?
    Yes, a struct can have member functions
  • What are the uses of arrays in structs?
    • Store multiple values of the same type
    • Organize data within a struct