Memory Alloction
1. What is the return type of malloc() or calloc()?
A. int *
B. int **
C. void *
D. void **
View Answer
Ans : C
Explanation: malloc() and calloc() return void *, without void * we may get warning in C if we don't type cast the return type to appropriate pointer.
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
Ans : B
Explanation: free() is used to free the memory spaces allocated by malloc() and calloc().
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
Ans : C
Explanation: #include<stdlib.h> is a header filer, which contains the inbuilt functions for all memory allocation functions.
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
Ans : D
Explanation: None
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
Ans : B
Explanation: No Explanation
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
Ans : D
Explanation: No Explanation.
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
Ans : D
Explanation: No Explanation.
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
Ans : C
Explanation:2 library functions to dynamically allocate memory is malloc() and calloc().
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
Ans : B
Explanation: No Explanation.
10.malloc() allocates memory from the heap and not from the stack.
A. True
B. False
View Answer
Ans : A
Explanation:No Explanation.
Also check :
Discussion