Structs C++ - Reading Assignments

Why do we need structs?

Answer: We need structs if the developer have collection of value-types i.e. string and int. Thanks to structs the program get’s better performance.

What are members in a struct?

Variables.

How do you access a member inside a struct?

The developer access members with a dot i.e. p.name, p.age and p.gender.

What is a nested struct?

It is structs inside structs i.e. one structs can be declared inside another structs exactly as the developer declare structs members inside a struct.

1 Like

Why do we need structs?

A struct (short for structure) allows us to group variables of mixed data types together into a single unit.

What are members in a struct?

variables that are part of the struct are called members (or fields)

How do you access a member inside a struct?

In order to access the individual members, we use the member selection operator (which is a period)

What is a nested struct?

Structs that contain other structs

1 Like

1.) We need structs to organize different types of variables into single groupings. Structs are also known as “aggregate data types”.
2.)Members are variables contained within a struct. They are the defining features of the struct itself.
3.)In order to access a member inside a struct we must use a “Member selector variable”, which is a period.
4.)A nested struct is a struct within a struct!

1 Like
  • Why do we need structs?
    For group multiple variables in an struct.

  • What are members in a struct?
    Members are variables( any variable: string, int, double etc)

  • How do you access a member inside a struct?
    struct.member

  • What is a nested struct?
    We have a struck inside another struck as a variable

2 Likes
  1. “A struct allows us to group variables of mixed data types together into a single unit.” - https://www.learncpp.com/cpp-tutorial/47-structs/
  2. Members are variable in a struct.
  3. " In order to access the individual members, we use the member selection operator (which is a period)." - https://www.learncpp.com/cpp-tutorial/47-structs/
  4. A nested struct, is a struct contained within another struct.
1 Like
  1. Structs are used to store more than one variable in an object.

  2. Variables that are part of structs are called members.

  3. A period or member selection operator is used to access struct members. i.e. struct.member

  4. A nested struct contains one or multiple structs in a struct.

1 Like
  1. Why do we need structs?
    We can use struct to store variables that represent an object.

  2. What are members in a struct?

The variable of the struct.

  1. How do you access a member inside a struct?

struct.member

  1. What is a nested struct?

When one struct has another struct like member

1 Like
  1. Why do we need structs?
    To group multiple individual variables together, in that way we can characterize “something” (object).

  2. What are members in a struct?
    The variables that are part of the struct.

  3. How do you access a member inside a struct?
    We use the member selection operator (.)
    Ex: struct.member

  4. What is a nested struct?
    A struct that contains other struct.

2 Likes

Its a struct within a struct. :slight_smile:

3 Likes

inception! haha :slight_smile:

Q1. Why do we need structs?

A1. In order to have more than one variable to represent an object - i.e. to create an aggregate data type

Q2. What are members in a struct?

A2. Variables that are part of the struct which can be referred to/thought of as fields

Q3. How do you access a member inside a struct?

A3. Using the “member selection operator” - i.e. a “period”, e.g. syntax format: struct.member

Q4. What is a nested struct?

A4. A (parent) struct that contains a member in the form of another (child) struct

1 Like
  1. Why do we need structs?
    A: A “struct” allows us to group variables of mixed data types together into a single unit. It makes things easier than having multiple independent variables that are not grouped in any way.

  2. What are members in a struct?
    A: The variables that are part of the struct are called “members” (or fields).

  3. How do you access a member inside a struct?
    A: struct.member

  4. What is a nested struct?
    A: A structure within a structure.

1 Like
  1. Why do we need structs?
    to define new data types that are not available by default.
  2. What are members in a struct?
    variables and default data types , like int , string , boolean or double
  3. How do you access a member inside a struct?
    by calling structName.variable
  4. What is a nested struct?
    a member in a struct can be another struct type. So basically an struct inside another struct
1 Like

Why do we need structs? A structure creates a data type that can be used to group items of possibly different types into a single type.

  1. What are members in a struct?
    A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths.

  2. How do you access a member inside a struct? To access the members of the inner structure, we write a variable name of the outer structure, followed by a dot( . ) operator, followed by the variable of the inner structure, followed by a dot( . ) operator, which is then followed by the name of the member we want to access.
    4.What is a nested struct?
    Nested structure in C is nothing but structure within structure. One structure can be declared inside other structure as we declare structure members inside a structure. The structure variables can be a normal structure variable or a pointer variable to access the data.
    use the member selection operator (which is a period). Here is an example of using the member selection operator to initialize each member variable:
    Employee joe; // create an Employee struct for Joe
    joe.id = 14; // assign a value to member id within struct joe

1 Like
  1. A struct (short for structure) allows us to group variables of mixed data types together into a single unit.
  2. Variables that are part of the struct are called members (or fields).
  3. You use the member selection operator (which is a period).
  4. Structs that can contain other structs are nested.
1 Like

Structs allow for easy storage and passing of large amounts of information.

Members are the stored variables inside a struct.

By using the member selection operator, a period.

A struct within another struct.

1 Like

1 To be able to custom made our variable. It is very good for many data for many users like account creation with personal details.
2 Members are variables of the struct
3 structName.memberName
4 This is when a strut has a another strut like a member

1 Like
  1. We need struct (short for structure) to group variables of mixed data types together into a single unit.

  2. The variables that are part of the struct are called members.

  3. In order to access the individual members of a struct, we use the member selection operator (which is a period).

  4. Nested struct is when a struct contain another struct.

2 Likes
  • We need structs because they allow us to define our own data type, using grouped variables of mixed data types into a single data type.
    Since structs are user defined, we have to declare them with the struct keyword.

  • Members are variables that are part of the struct within the struct body.

  • In order to access a member inside a struct, we use the member selection operator (a period)

  • A nested struct is a struct that contains another struct.

1 Like
  1. Why do we need structs?
    Structs are used for lightweight objects such as Rectangle, color, Point, etc. Unlike class, structs in C++ are value type than reference type. It is useful if you have data that is not intended to be modified after creation of struct. C++ Structure is a collection of different data types.

  2. What are members in a struct?
    Data Member: These members are normal C++ variables. We can create a structure with variables of different data types in C++.
    Member Functions: These members are normal C++ functions. Along with variables, we can also include functions inside a structure declaration.

  3. How do you access a member inside a struct?
    struct.memberDataType

  4. What is a nested struct?
    nested structs are a useful way of organizing your code, and perhaps even restricting what others can do with it. In essence, a nested type is just one data type defined inside another:

Struct Deck {
Struct Card {
}
}
1 Like