Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

malloc() and free()

Name: Anonymous 2011-01-18 22:44

#include <stdlib.h>

int * b;

int main(void)
{
    int * a = NULL;
    a = (int *) malloc(sizeof(int));
    b = &a;
    free(b);
    return 0;
}


Would this result in a memory leak? If yes, why?

Name: Anonymous 2011-01-22 7:00

>>43
In C, the only thing you need to know is:
You need to cast void* only when you have to dereference it.
You don't dereference void*.
When you need to dereference void*, you assign the pointer to another pointer with the correct type instead of working on the casted void*.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List