Home »
MCQs »
C++ MCQs
What problem may occur with the below code?
164. What problem may occur with the below code?
#include <stdio.h>
int main()
{
float* ptr = (int*)malloc(sizeof(float));
ptr = NULL;
free(ptr);
}
Options:
- Memory leak
- Dangling pointer
- Compiler error
- None of the above
Answer: A) Memory leak
Explanation:
The above program will create a memory leak because we assigned the NULL to the pointer and free the pointer.