Complete the code to allocate memory for an integer pointer.
int *ptr = (int *)[1](sizeof(int));The malloc function allocates memory dynamically. Here, it allocates enough space for one integer.
Complete the code to release the allocated memory.
free([1]);The free function releases the memory previously allocated by malloc. You must pass the pointer to the allocated memory.
Fix the error in the code to avoid memory leak by freeing the allocated memory.
int *arr = (int *)malloc(5 * sizeof(int)); // Missing [1] here return 0;
To avoid memory leaks, you must call free on the allocated pointer before the program ends or when the memory is no longer needed.
Fill both blanks to correctly allocate and free memory for a character array.
char *buffer = (char *)[1](100 * sizeof(char)); // Use the buffer [2](buffer);
First, allocate memory with malloc. After using the buffer, release the memory with free to avoid leaks.
Fill all three blanks to create a memory leak by allocating memory without freeing it.
int *data = (int *)[1](10 * [2](int)); // Forgot to [3] data, causing a memory leak.
The code allocates memory with malloc and uses sizeof to get the size of int. The comment correctly identifies that it forgot to call free(data), causing a memory leak.