Exercise

1. What is the return type of malloc() or calloc()?

A. int *
B. int **
C. void *
D. void **

View Answer


2. Which function is used to delete the allocated memory space?

A. Dealloc()
B. free()
C. Both a and b
D. either a or b

View Answer


3.Among 4 header files, which should be included to use the memory allocation functions like malloc(), calloc(), realloc() and free()?

A. #include<string.h>
B. #include<memory.h>
C. #include<stdlib.h>
D. Both b and c

View Answer


4. Which of the following is/are true

A. calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has random data.
B. malloc() and memset() can be used to get the same effect as calloc()
C. Both malloc() and calloc() return 'void *' pointer
D. All of the above

View Answer


5. Which of the following is true?

A. "ptr = calloc(m, n)" is equivalent to following
     ptr = malloc(m * n);
B. "ptr = calloc(m, n)" is equivalent to following
     ptr = malloc(m * n); memset(ptr, 0, m * n);
C. "ptr = calloc(m, n)" is equivalent to following
     ptr = malloc(m); memset(ptr, 0, m);
D. "ptr = calloc(m, n)" is equivalent to following
     ptr = malloc(n); memset(ptr, 0, n);

View Answer


6. Which languages necessarily need heap allocation in the run time environment?

A. Those that support recursion
B. Those that use dynamic scoping
C. Those that use global variables
D. Those that allow dynamic data structures

View Answer


7. Which of the following statement is correct prototype of the malloc() function in c ?

A. int* malloc(int);
B. Char* malloc(char);
C. unsigned int* malloc(unsigned int);
D. void* malloc(size_t);

View Answer


8. Specify the 2 library functions to dynamically allocate memory?

A. malloc() and memalloc()
B. alloc() and memalloc()
C. malloc() and calloc()
D. memalloc() and faralloc()

View Answer


9. malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's. A.

A. True
B. False

View Answer


10.malloc() allocates memory from the heap and not from the stack.

A. True
B. False

View Answer



Discussion

* You must be logged in to add comment.