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 pointed to by ptr.
Fix the error in the code to allocate memory for 5 integers.
int *arr = (int *)malloc([1] * sizeof(int));To allocate memory for 5 integers, multiply 5 by the size of an integer.
Fill both blanks to create a loop that initializes the allocated array to zero.
for (int [1] = 0; [2] < 5; [1]++) { arr[[1]] = 0; }
The variable i is used as the loop counter consistently in all parts of the for loop.
Fill all three blanks to safely allocate memory and check if allocation succeeded.
int *ptr = (int *)[1](sizeof(int) * [2]); if ([3] == NULL) { printf("Memory allocation failed\n"); return 1; }
Use malloc to allocate memory for 10 integers. Then check if ptr is NULL to detect failure.
