Quiz Yourself on Heap and Dynamic Memory Allocations
Test your understanding of the material presented in this chapter.
Heap and dynamic memory allocations
1
What is the output of the following code? Assume the allocation doesn’t fail.
int* arr = malloc(sizeof(int) * 5);
if(arr == NULL)
{
return;
}
printf("%d\n", arr[3]);
A)
The memory block is uninitialized, and the code prints garbage values.
B)
The memory block is initialized by default with 0
. The code prints 0
.
C)
The code will crash because arr[3]
is not a valid memory location.
D)
The code doesn’t compile.
Question 1 of 90 attempted
Get hands-on with 1400+ tech skills courses.