C alloc / free struct arr

68 Views Asked by At

I want to be sure it's correct because idk how to verify it surelly without any complex tools or trackers (maybe it's possible \w gdb). I malloc arr of struct as this:

typedef struct {
     int a;
} A;
A *arr = malloc(sizeof *arr * 5);
arr[2].a = -9;

Then to free a simple

free(arr); //because it's not an array of pointers of structs

Is it correct way to free ?

0

There are 0 best solutions below