24 Lecture
CS201
Midterm & Final Term Short Notes
Memory Allocation
Memory allocation is the process of assigning a block of memory to a program for storing data during runtime. In C programming, memory allocation is done using functions such as malloc(), calloc(), and realloc(). Proper memory allocation is crit
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is memory allocation in C programming? a) Reserving memory for the program to store data during runtime b) Allocating memory for the program during compile time c) Storing data in memory during runtime d) None of the above
Answer: a) Reserving memory for the program to store data during runtime
- Which of the following is a function used for dynamic memory allocation in C? a) calloc() b) malloc() c) realloc() d) All of the above
Answer: d) All of the above
- What is the difference between malloc() and calloc() functions? a) malloc() allocates a block of memory of a specified size, while calloc() initializes the memory to 0 b) calloc() allocates a block of memory of a specified size, while malloc() initializes the memory to 0 c) malloc() and calloc() are the same function d) None of the above
Answer: a) malloc() allocates a block of memory of a specified size, while calloc() initializes the memory to 0
- What happens if malloc() or calloc() is unable to allocate the requested memory? a) The program crashes b) The function returns NULL c) The function returns a negative value d) None of the above
Answer: b) The function returns NULL
- What is a memory leak? a) When memory is not deallocated after it is no longer needed b) When memory is allocated but never used c) When memory is allocated and used but not freed after it is no longer needed d) None of the above
Answer: a) When memory is not deallocated after it is no longer needed
- Which function is used to free memory allocated by malloc(), calloc(), or realloc()? a) dealloc() b) free() c) remove() d) None of the above
Answer: b) free()
- What is stack memory allocation? a) Reserving memory for the program during runtime b) Allocating memory for the program during compile time c) Storing data in memory during runtime d) None of the above
Answer: b) Allocating memory for the program during compile time
- What is heap memory allocation? a) Reserving memory for the program during runtime b) Allocating memory for the program during compile time c) Storing data in memory during runtime d) None of the above
Answer: a) Reserving memory for the program during runtime
- What is the purpose of the realloc() function in C programming? a) To allocate a new block of memory b) To deallocate a block of memory c) To resize an existing block of memory d) None of the above
Answer: c) To resize an existing block of memory
- What is the potential risk of not properly managing memory allocation in C programming? a) Memory leaks b) Memory fragmentation c) Program crashes d) All of the above
Answer: d) All of the above
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is dynamic memory allocation? Answer: Dynamic memory allocation is the process of allocating memory to a program during runtime. In C programming, it is done using functions like malloc(), calloc(), and realloc().
What is the difference between stack memory and heap memory? Answer: Stack memory is allocated during compile time, whereas heap memory is allocated during runtime. Stack memory is limited in size and is used for static memory allocation, while heap memory is used for dynamic memory allocation.
What is the purpose of the malloc() function in C programming? Answer: The malloc() function is used to dynamically allocate memory to a program during runtime.
What is a memory leak? Answer: A memory leak is a situation where memory that has been allocated is not properly deallocated, leading to the gradual depletion of available memory.
What is the purpose of the calloc() function in C programming? Answer: The calloc() function is used to dynamically allocate memory to a program during runtime, and it initializes the memory to 0.
What is the purpose of the free() function in C programming? Answer: The free() function is used to deallocate memory that has been allocated using malloc(), calloc(), or realloc().
What is the potential danger of not properly deallocating memory in a program? Answer: The potential danger is that memory leaks can occur, causing the program to eventually run out of available memory.
What is memory fragmentation? Answer: Memory fragmentation is a situation where the available memory becomes fragmented and is no longer contiguous, making it difficult to allocate large blocks of memory.
What is the purpose of the realloc() function in C programming? Answer: The realloc() function is used to resize an existing block of memory that has been allocated using malloc(), calloc(), or realloc().
What is the maximum amount of memory that can be allocated using malloc() in C programming? Answer: The maximum amount of memory that can be allocated using malloc() depends on the system and available memory, but it is typically limited to a few gigabytes.