Зміст курсу
C Structs
C Structs
Struct with Arrays and Other Structs
In some structures there is a need to use an entire array of nested structures to describe more complex objects.
To get access to the required array element of a nested structure, you must:
- Refer to the external structure;
- Using an index, access the required field of an array of nested structures;
- Refer to the required field of the nested structure.
For example:
Let's look at an example of a structure representing information about a student and his courses at a university. Each student will have a name, age, and an array of courses they are taking. Each course will contain the title, instructor and number of credits.
Завдання
- In the
Course
structure, declare an arraycourseName
, which will contain the name of the course; - In the
Student
structure, declare an arraystudentName
to store the student's name. - In the
Student
structure, initialize thecourses
array, consisting of two nestedCourse
structures. - Use a loop to display course information.
Дякуємо за ваш відгук!
Struct with Arrays and Other Structs
In some structures there is a need to use an entire array of nested structures to describe more complex objects.
To get access to the required array element of a nested structure, you must:
- Refer to the external structure;
- Using an index, access the required field of an array of nested structures;
- Refer to the required field of the nested structure.
For example:
Let's look at an example of a structure representing information about a student and his courses at a university. Each student will have a name, age, and an array of courses they are taking. Each course will contain the title, instructor and number of credits.
Завдання
- In the
Course
structure, declare an arraycourseName
, which will contain the name of the course; - In the
Student
structure, declare an arraystudentName
to store the student's name. - In the
Student
structure, initialize thecourses
array, consisting of two nestedCourse
structures. - Use a loop to display course information.
Дякуємо за ваш відгук!
Struct with Arrays and Other Structs
In some structures there is a need to use an entire array of nested structures to describe more complex objects.
To get access to the required array element of a nested structure, you must:
- Refer to the external structure;
- Using an index, access the required field of an array of nested structures;
- Refer to the required field of the nested structure.
For example:
Let's look at an example of a structure representing information about a student and his courses at a university. Each student will have a name, age, and an array of courses they are taking. Each course will contain the title, instructor and number of credits.
Завдання
- In the
Course
structure, declare an arraycourseName
, which will contain the name of the course; - In the
Student
structure, declare an arraystudentName
to store the student's name. - In the
Student
structure, initialize thecourses
array, consisting of two nestedCourse
structures. - Use a loop to display course information.
Дякуємо за ваш відгук!
In some structures there is a need to use an entire array of nested structures to describe more complex objects.
To get access to the required array element of a nested structure, you must:
- Refer to the external structure;
- Using an index, access the required field of an array of nested structures;
- Refer to the required field of the nested structure.
For example:
Let's look at an example of a structure representing information about a student and his courses at a university. Each student will have a name, age, and an array of courses they are taking. Each course will contain the title, instructor and number of credits.
Завдання
- In the
Course
structure, declare an arraycourseName
, which will contain the name of the course; - In the
Student
structure, declare an arraystudentName
to store the student's name. - In the
Student
structure, initialize thecourses
array, consisting of two nestedCourse
structures. - Use a loop to display course information.