Here is the example:
#include <stdio.h>
struct nums {
int x;
int y;
};
int main() {
struct nums *ball = malloc(sizeof *ball * 4);
ball[0].x = 2;
printf("%d", ball[0].x);
free(ball);
};
Error Details:
Exception thrown: write access violation.
**ball** was 0x6E919550.
I am very new to C and I would really appreciate someone to explain what specifically I am telling the computer to do here, why it is incorrect and also show me the correct way of doing this. Thanks.
EDIT: This seems to be functional code but does not run when I compile and run it in VS16 why could this be?