Initializing a pointer in a separate function in C
You need to adjust the *a pointer, this means you need to pass a pointer to the *a. You do that like this: int *a; void initArray( int **arr ) { *arr = malloc( sizeof( int ) * SIZE ); } int main() { initArray( &a ); return 0; }