"Initializing" the pointer in the separate function in C

Posted by pechenie on Stack Overflow See other posts from Stack Overflow or by pechenie
Published on 2010-03-21T06:38:33Z Indexed on 2010/03/21 6:41 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

I need to do a simple thing, which I used to do many times in Java, but I'm stuck in C (pure C, not C++). The situation looks like this:

int *a;

void initArray( int *arr )
{
    arr = malloc( sizeof( int )  * SIZE );
}

int main()
{
    initArray( a );
    // a is NULL here! what to do?!
    return 0;
}

I have some "initializing" function, which SHOULD assign a given pointer to some allocated data (doesn't matter). How should I give a pointer to a function in order to this pointer will be modified, and then can be used further in the code (after that function call returns)?

Thanx for help.

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointer