Memory Allocation MCQs
Practice free Memory Allocation multiple-choice questions with instant answer feedback and step-by-step solutions. Click an option to check yourself, reveal the full explanation, and work through all 62 questions — no login required.
Question 46hard
What will be the error (if any) in the following C code?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p;
*p = (char)calloc(10);
strcpy(p, "HELLO");
printf("%s", p);
free(p);
return 0;
}Question 47hard
What will happens if the statement free(a) is removed in the following C code?
#include<stdio.h>
#include<stdlib.h>
main()
{
int *a;
a=(int*)malloc(sizeof(int));
*a=100;
printf("*a%d",*a);
free(a);
a=(int*)malloc(sizeof(int));
*a=200;
printf("a%p",a);
*a=200;
printf("a%d",*a);
}Question 48medium
In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory . . . . . . . .
Advertisement
Question 49hard
What will be the output of the following C code if it is executed on a 32 bit processor?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}Question 50easy
Garbage collector frees the programmer from worrying about . . . . . . . .
Question 51hard
Suppose we have a one dimensional array, named 'x', which contains 10 integers. Which of the following is the correct way to allocate memory dynamically to the array 'x' using malloc()?
Advertisement
Question 52medium
Queue data structure works on the principle of . . . . . . . .
Question 53easy
Which of the following is an example of static memory allocation?
Question 54hard
What will be the output of the following C code? (Given that the size of array is 4 and new size of array is 5)
#include<stdio.h>
#include<stdlib.h>
main()
{
int *p,i,a,b;
printf("Enter size of array");
scanf("%d",&a);
p=(int*)malloc(a*sizeof(int));
for(i=0;i<a;i++)
printf("%d\n",i);
printf("Enter new size of array");
scanf("%d",&b);
realloc(p,b);
for(i=0;i<b;i++)
printf("%d\n",i);
free(p);
}