Hi! I have problems with an array of structs. This is an example of my problem.
Segmetation fault is the error. Why?Code:#include <stdio.h> #include <stdlib.h> int size = 0; struct a{ int x; }; void add(struct a *as){ as = realloc(as, size++ * sizeof(struct a)); as[size - 1].x = size; printf("%d\n", as[size -1].x); } int main(){ struct a *as = NULL; add(as); printf("%d\n", as[size - 1].x); return 0; }