My program does not print anything and fails [closed]

The variable p doesn’t point to anywhere. The memory there is just garbage value. So, either do:

p = malloc(sizeof(struct data));

This will allocate some memory on the heap and store the address in p.

Or,

p = &<some valid memory>;

I think you intended to do:

p = &d;

Which would store the address of d in p.

Leave a Comment