Consider the following function:
void free_or_not ( int count ) { int i ; int *ip = malloc ( count * sizeof ( int ) ) ; for ( i = 0 ; i < count ; i ++ ) ip[i] = i ; for ( i = 0 ; i < count ; i ++ ) printf ( "%d\n" , ip[i] ) ; free ( ip ) ; }
Will it cause a memory leak if I don't call free()inside free_or_not()?
free()
free_or_not()
Yes, when your function ends, you will lose the pointer to the allocated memory to free ().
Yes, it will cause a memory leak. Once your function completes, you have no pointers to the allocated memory on free().
:. void * ( ) (ip) , tn free() .
void *
ip