Programming for Problem Solving (3110003) MCQs

MCQs of Dynamic memory allocation

Showing 1 to 10 out of 19 Questions
1.
Difference between calloc() and malloc()
(a) calloc() takes a single argument while malloc() needs two arguments
(b) malloc() takes a single argument while calloc() needs two arguments
(c) malloc() initializes the allocated memory to ZERO
(d) calloc() initializes the allocated memory to NULL
Answer:

Option (b)

2.
Which function reallocates memory?
(a) realloc
(b) calloc
(c) malloc
(d) None of these
Answer:

Option (a)

3.
Which of the following header files must necessarily be included to use dynamic memory allocation functions?
(a) stdlib.h
(b) stdio.h
(c) memory.h
(d) dos.h
Answer:

Option (a)

4.
What is correct about malloc() function?
(a) Allocates the memory of requested size.
(b) Returns the pointer to the first byte of allocated space.
(c) Returns the pointer to the first byte of allocated space.
(d) All of these
Answer:

Option (d)

5.
The number of arguments taken as input which allocating memory dynamically using malloc() is _______
(a) 0
(b) 1
(c) 2
(d) 3
Answer:

Option (b)

6.
Which of the following statement is correct for the malloc() function in C?
(a) int* malloc(int);
(b) char* malloc(char);
(c) unsigned int* malloc(unsigned int);
(d) void* malloc(size_t);
Answer:

Option (d)

7.
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()?
(a) x=(int*)malloc(10);
(b) x=(int*)malloc(10,sizeof(int));
(c) x=malloc(int 10,sizeof(int));
(d) x=(int*)malloc(10*sizeof(int));
Answer:

Option (d)

8.
What is the output?

void main()
{
    int *p;
    p = (int *)malloc(20); /* Assume p has address of 1314 */
    printf("%d", p);
}

(a) 1314
(b) 1316
(c) NULL
(d) void
Answer:

Option (a)

9.
What is the output?

void main()
{
    int *p;
    p = (int *)malloc(20);
    printf("%d", sizeof(p));
}

(a) 4
(b) 2
(c) 8
(d) Garbage value
Answer:

Option (b)

10.
Which function is used to delete the allocated memory space?
(a) dealloc()
(b) free()
(c) both a and b
(d) delete()
Answer:

Option (b)

Showing 1 to 10 out of 19 Questions