I am trying to allocate and initialize an array inside a function, but I cannot get 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 is a lot of documentation on pointers there, but I did not find this particular case. Any tips on what I'm doing wrong?
source
share