I'm teaching a friend C. We were working with structs and pointers and I gave him a program to try out on his computer. We were going to deconstruct the program line by line so he could understand how structs and pointers worked together. On my end, I get this result:
Value of a in astr is 5
Value of b in astr is 5.550000
Value of c in astr is 77
Value of d in astr is 888.888800
On his computer, the program mostly worked except for the last value of astr->d which printed out some very large negative number. So my question is, why does this happen on his computer, but work fine on mine? below is the offending code:
#include <stdio.h>
#include <stdlib.h>
int main(){
    struct a_struct{
        int a;
        float b;
        int c;
        double d;
    };
    struct a_struct* astr;
    astr = (struct a_struct*)malloc(sizeof(astr));
    astr->a = 5;
    astr->b = 5.55;
    astr->c = 77;
    astr->d = 888.8888;
    printf("Value of a in astr is %d\n", astr->a);
    printf("Value of b in astr is %f\n", astr->b);
    printf("Value of c in astr is %d\n", astr->c);
    printf("Value of d in astr is %lf\n", astr->d);
    return 0;
}
 
     
     
    