Home Subjects C Programming Dynamic Memory

C Programming
Dynamic Memory

C language from basics to advanced placement prep

53 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–53 of 53
Topics in C Programming
Q.51 Medium Dynamic Memory
What happens when you try to access memory after calling free()?
A Automatic reallocation
B Use-after-free error (undefined behavior)
C Returns NULL
D Program terminates gracefully
Correct Answer:  B. Use-after-free error (undefined behavior)
EXPLANATION

Accessing freed memory results in undefined behavior and is a critical bug. The memory may be reallocated for other purposes.

Test
Q.52 Medium Dynamic Memory
What is a memory leak in C?
A Accessing freed memory
B Allocated memory that is never freed
C Memory overflow
D Stack overflow
Correct Answer:  B. Allocated memory that is never freed
EXPLANATION

A memory leak occurs when allocated memory is not freed, consuming system resources without releasing them back.

Test
Q.53 Medium Dynamic Memory
What will be the output of the following code?
int *ptr = malloc(sizeof(int));
if(ptr == NULL) printf("Failed");
else printf("Success");
A Failed
B Success
C Compilation Error
D Runtime Error
Correct Answer:  B. Success
EXPLANATION

In typical scenarios, malloc() successfully allocates memory and returns non-NULL pointer, printing 'Success'. NULL check is good practice for error handling.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips