For example, the following code:
#include <stdio.h>
struct exemplo{
char letra;
int numero;
float flutuante;
};
int main()
{
printf("Tamanho do char: %u\n", sizeof(char));
printf("Tamanho do int: %u\n", sizeof(int));
printf("Tamanho do float: %u\n", sizeof(float));
printf("Tamanho da struct: %u\n", sizeof(struct exemplo));
}
Show in console:
Tamanho do char: 1
Tamanho do int: 4
Tamanho do float: 4
Tamanho da struct: 12
That is, the size of the struct is 12 instead of 9 (1 + 4 + 4) as expected. Why does this happen?