• Home
  • Textbooks
  • Data Structures Using C
  • Void Pointer and Dynamic Memory Management

Data Structures Using C

Amol M. Jagtap, Ajit S. Mali

Chapter 3

Void Pointer and Dynamic Memory Management - all with Video Answers

Educators


Chapter Questions

Problem 1

What is the return type of malloc() function?
A. float
B. int *
C. void *
D. double *

Check back soon!

Problem 2

Which of the below header files is required to be included to use dynamic memory allocation functions?
A. stdlib.h
B. stdio.h
C. memory.h
D. dos.h

Check back soon!

Problem 3

Which memory partition stores dynamically allocated variables?
A. Heap memory partition
B. Stack memory partition
C. Global memory partition
D. Code memory partition

Check back soon!

Problem 4

Which method is used to remove the dynamically allocated memory space?
A. dealloc() function
B. free() function
C. realloc() function
D. Both A and B

Check back soon!

Problem 5

Which of the following is correct function declaration for malloc() function in C language?
A. void * malloc ( int size_t)
B. char* malloc (char)
C. int * malloc (int size_t)
D. float * malloc (float size_t)

Check back soon!

Problem 6

Which functions are used for memory allocation at runtime in C language?
A. malloc() function
B. calloc () function
C. realloc 0 ) function
D. Both A and B

Check back soon!

Problem 7

What is the problem with following code?
```
#include <stdlib.h>
Ainclude<atdio.h>
vold fun 0)
l
Int *ptr = (lnt *) nalloc(s1zeof(1nt));
printf("\n Memory allocated dynanically for integer variable");
]
int main 0
1
fun ():
recurn 0;
1
```
A. Memory Leakage
B. Dangling pointer
C. Compiler error
D. None of the the above

Check back soon!

Problem 8

Consider the following program, where are $x, y$ and $z$ are stored in main memory partition?
```
int y;
int main()
f
int z = 0;
int *x = int * malloc( sizeof(int));
}
```
A. $\mathbf{x}$ is stored on the heap memory partition, $y$ is stored on the global partition and $z$ is stored on stack partition.
B. $x, y$ and $z$ variables are stored on the stack partition.
C. x is stored on the heap memory, y and z variables are stored on stack partition.
D. $x$ and $y$ are stored on the heap memory partition and $z$ is stored on stack partition.

Check back soon!

Problem 9

Which of the following functions allocates multiple blocks of memory at runtime, each block allocated having same size and each byte of allocated space is initialized to zero?
A. malloc()
B. realloc()
C. calloc()
D. free()

Check back soon!

Problem 10

Memory is reserved dynamically using malloc() or calloc() functions but memory area that is allocated dynamically is not accessible to programmer any more afterward is called as?
A. Dangling memory
B. Dangling pointer
C. Memory Leakage
D. Pointer leakage

Check back soon!

Problem 11

In realloc() library function, if the new size of the memory block is greater than the old size, then newly added memory space .?
$\qquad$
A. is initialized to one
B. is initialized to zero
C. is not initialized
D. none of the above

Check back soon!

Problem 12

What is dangling pointer?
A. if pointer is assigned NULL value
B. if pointer points to a memory location that has already been freed
C. if pointer is assigned to more than one variable
D. None of the above

Check back soon!

Problem 13

The free() function frees the memory allocated at runtime and returns
A. pointer value
B. the memory address of the freed variable
C. no value is return
D. an float value is return

Check back soon!

Problem 14

Which of the following function allocates requested size of bytes for single element and returns a pointer to first byte of allocated space at runtime and initial element value is garbage.
A. calloc() function
B. malloc() function
C. realloc() function
D. None of the above

Check back soon!

Problem 15

Which of the following pointer stores a defined value that is zero or NULL address.
A. NULL pointer
B. void pointer
C. Dangling pointer
D. None of the above

Check back soon!

Problem 16

Which of the following statements are correct?

Statement l: A NULL pointer stores a defined value that is zero or NULL address.
Statement 2: The void pointer is a data type while NULL pointer is not a data type.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 17

Which of the following statements are true or false?

Statement 1 : malloc 0 is static memory management function having return type as void*.
Statement 2: malloc () function reserves the memory dynamically on heap partition.
A. Statement $\mathbf{1}$ is false and Statement $\mathbf{2}$ is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 18

. Which of the following statements are true or false?

Statement 1: The realloc () function alters the size of the space already assigned.
Statement 2: The malloc $($ ) function assigns space for an array of elements, initializes them to zero.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 19

Which of the following statements are true or false?

Statement 1: Compile time storage of a variable is allocated and released by the compiler depends on the scope of variable and lifetime of a variable.
Statement 2: In dynamic allocation, the programmer is responsible to release the space when it is not required.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 20

Which of the following statements are true or false?

Statement 1: A memory leak occurs when a programmer creates a memory dynamically on heap partition and forget to delete it.
Statement 2: A dangling pointer points to a memory location that has previously been freed.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 21

Which of the following statements are true or false?

Statement 1 : The free 0 function releases the space previously assigned by the malloc $($, calloc 0 or realloc 0 function.
Statement 2: A dangling pointer and void pointers both are same.
A. Statement 1 is false and Statement 2 is true
B. Statement 2 is false and Statement 1 is true
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!