I have function that returns an array of structs. I want to access the value, but I get a segmentation fault.
Minimal reproduction:
#include <stdio.h>
struct example {
int val;
};
struct example* get() {
struct example out[1];
struct example item = {123};
out[0] = item;
return out;
}
int main() {
struct example *items;
items = get();
printf("%d\n", items[0].val);
return 0;
}
It should print 123
.