Initializing a struct outside of main() using malloc (C89) : <p>I'm trying to implement a doubly linked list in C and I need to use an initialize function, while maintaining a size field. My code is as follows:</p>

<pre><code>typedef struct element{
    struct element* next;
    struct element* prev;
    int value;
}element_t;

typedef struct linkedlist{
    element_t* head;
    element_t* tail;
    int size;
}linkedlist;

void init(linkedlist* list){
    list = malloc(sizeof(linkedlist));
    list-&gt;size = 0;
}

int main(int argc, char** argv){
    linkedlist* list;
    init(list);
    return 0;
</code></pre>

<p>When I'm trying to access list->size in the init function, I get the correct value, But when I try to access list->size from main the program returns a strange, large negative value (probably an address in hex).</p>

<p>Would like to know what I'm doing wrong. stdlib is included.</p>
