Q4 problem with the code

I tried running the program on codeblocks and it only gave me warning about to include stdlib i did not got any other error please explain the correct answer

hi shubham
it is so because first the memory is allocated to pointer using malloc(1st statement)
then the pointer is made to point to NULL. after that free statement is used which frees up the memory of ptr=NULL not the one allocated before. thus it leads to memory leak

1 Like