Programming for Problem Solving (3110003) MCQs

MCQs of Dynamic memory allocation

Showing 11 to 19 out of 19 Questions
11.
What is the output if it is executed on a 32 bit processor?

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

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

Option (a)

12.
What is correct about calloc() function?
(a) Allocates the space for elements of an array.
(b) Initializes the elements to zero.
(c) If space is insufficient returns a NULL pointer.
(d) All of these
Answer:

Option (d)

13.
When the pointer is NULL, then the function realloc is equivalent to the function ________
(a) malloc()
(b) calloc()
(c) free()
(d) alloc()
Answer:

Option (a)

14.
If malloc() and calloc() are not type casted, the default return type is _____
(a) void*
(b) void**
(c) int*
(d) char*
Answer:

Option (a)

15.
Which of the following functions allocates multiple blocks of memory, each block of the same size?
(a) malloc()
(b) realloc()
(c) calloc()
(d) free()
Answer:

Option (c)

16.
What if functionality if realloc() function?
(a) Change the location of memory allocated by malloc() or calloc().
(b) Reallocates memory deleted by free() function.
(c) It is used to modify the size of the previously allocated memory space.
(d) None of these
Answer:

Option (c)

17.
What is the output?

void main()
{
    char *p = calloc(100, 1);
    p = "welcome";
    printf("%s", p);
}

(a) Address of p
(b) welcome
(c) Garbage value
(d) Error
Answer:

Option (b)

18.
What is the output?

void main()
{
    int *ptr;
    ptr = (int *)calloc(1,sizeof(int));
    *ptr = 10;
    printf("%d\n",*ptr);
}

(a) 0
(b) -1
(c) 10
(d) NULL
Answer:

Option (c)

19.
What is the output?

void main()
{
    int *ptr;
    ptr = (int *)calloc(1,sizeof(int));
    printf("%d\n",*ptr);
}

(a) 0
(b) -1
(c) Error
(d) Null
Answer:

Option (a)

Showing 11 to 19 out of 19 Questions