I'm new to C so please correct any mistakes I have.
Here's some code that's sort of like the code I have
//typdef stuff for apple, *apple_t here
apple_t get() {
apple a;
a.num = 0;
apple_t ap = &a;
printf("set num to %d\n", ap->num);
return ap;
}
// ap above is placed into read(ap)
void read(apple_t ap) {
printf("num: %d\n", ap->num);
}
Why is it that for the "set" print ap->num == 0, but when I do the printf in read function I get some junk number like -1218550893? What's going on? Is the integer set being freed? What is C doing? And how do you fix this?