I have a question, just doing some test, trying to build a iterator (Opp) in c, but when i started, I saw that when i create a struct that only had "int a" and "int b", the struct would initialize the values by itself at 0 (I know that this is undefined behavior and i shouldn't do it) but everytime I run the code the values where 0, but when i added a string to a struct, the string is set to null by itself, but the integers add garbage values (even if i try to pack the struct, I thought it was because of the padding of the struct), can someone explain me if this is just random or does it have a reason?
typedef struct st {
int a;
int b;
} st;
int main(void)
{
st my;
printf("a: %d\n", my.a); // always 0
printf("b: %d\n", my.b); // always 0
return (0);
}
typedef struct st {
int a;
int b;
char *str;
} st;
int main(void)
{
st my;
printf("a: %d\n", my.a); // Random value
printf("b: %d\n", my.b); // Random value
printf("str: %s\n", my.str); // Always NULL
return (0);
}