I've already learned how to use the command in a code, but I still do not understand exactly what it's for. Could someone explain me, with examples if possible, its usefulness?
I've already learned how to use the command in a code, but I still do not understand exactly what it's for. Could someone explain me, with examples if possible, its usefulness?
The struct is basically used to group variables that have a common goal and create new data types. Technically, the struct will physically align this data in memory allowing it to be accessed by a single access point. For example: If you need to store a person's data such as 'name', 'age', 'gender', etc., define a struct called 'person' with the data you need.
struct pessoa {
char *nome;
unsigned int idade;
char genero[1]; // M ou F
};
// Declaração da variável p utilizando a struct pessoa
struct pessoa p;
// Definição dos valores.
p.nome = "Joao";
p.idade = 12;
p.genero = 'M';