Can someone tell me what I am doing wrong? I want to pass a NULL pointer to a function which will allocate some memory to it and assign it values. Then I want to be able to access the values outside of the function. This is probably an easy fix, but the solution is escaping me.
Code:void test(int* tmp); void main(void) { int* data = NULL; test(data); printf("%d %d\n",data[0], data[1]); } void test(int* tmp) { tmp = (int *)malloc(sizeof(int)*2); *tmp[0] = 1; *tmp[1] = 2; }