Course Object Oriented Programming

Structs in C

Course's Page 16 min Text by
User Image
Abacate

Hello, in this class you will learn about structs in C, because, as already said, during the course we will slowly migrate from C language to C++. Let's go!

Representation Problem

Imagine the following problem:

How to represent a type of data that stores the student's data?

We know that a student has a name (vector of char) and an age (integer).

Note then that the problem requires a structure that stores different types (char and integer).

Heterogeneous Structure

Vectors are homogeneous structures, as they only store data of the same type.

Therefore, to create structures that store data of different types, such as the name and age, we have to use structs.

Structs are defined by the programmer and can store various types of information (heterogeneous structure).