I'm trying to allocate and initialize an array inside a function, but I can't seem to fetch the values after returning.
This was my last almost-working attempt
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int func(int **thing);
int main() {
int *thing;
func(&thing);
printf("%d %d", thing[0], thing[1]);
}
int func(int **thing) {
*thing = calloc(2, sizeof(int));
*thing[0] = 1;
*thing[1] = 2;
printf("func - %d %d \n", *thing[0], *thing[1]);
}
but the values printed outside the function are 1 and 0. There are lots of documentation on pointers out there, but I haven't found this specific case covered. Any tips on what I'm doing wrong ?