Vidyalelo
C Programming · all questions

Memory Allocation
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

62

Questions

3/4

Page

Pick an option on a question to see the right answer and solution.

The following C code is an example of . . . . . . . .
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
    char *p,*q;
    p=(char*)malloc(3*sizeof(char));
    q=p;
    strcpy(p,"hello");
    printf("p=%s",p);
    printf("q=%s",q);
    free(q);
    q=NULL;
    gets(p);
    gets(q);
    printf("%s",p);
    printf(“%s”,q);
}

Select an option to see the answer and solution.

If malloc() and calloc() are not type casted, the default return type is . . . . . . . .

Select an option to see the answer and solution.

Which of the following functions allocates multiple blocks of memory, each block of the same size?

Select an option to see the answer and solution.

A condition where in memory is reserved dynamically but not accessible to any of the programs is called . . . . . . . .

Select an option to see the answer and solution.

Which of the following header files must necessarily be included to use dynamic memory allocation functions?

Select an option to see the answer and solution.

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;
}

Select an option to see the answer and solution.

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);
}

Select an option to see the answer and solution.

In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory . . . . . . . .

Select an option to see the answer and solution.

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;
}

Select an option to see the answer and solution.

Garbage collector frees the programmer from worrying about . . . . . . . .

Select an option to see the answer and solution.

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()?

Select an option to see the answer and solution.

Queue data structure works on the principle of . . . . . . . .

Select an option to see the answer and solution.

Which of the following is an example of static memory allocation?

Select an option to see the answer and solution.

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);
}

Select an option to see the answer and solution.

The type of linked list in which the node does not contain any pointer or reference to the previous node is . . . . . . . .

Select an option to see the answer and solution.

In the function malloc(), each byte of allocated space is initialized to zero.

Select an option to see the answer and solution.

The number of arguments taken as input which allocating memory dynamically using malloc() is . . . . . . . .

Select an option to see the answer and solution.

Choose the statement which is incorrect with respect to dynamic memory allocation.

Select an option to see the answer and solution.

Pick out the correct statement with respect to the heap.

Select an option to see the answer and solution.

The size of both stack and heap remains the same during run time.

Select an option to see the answer and solution.