C Programming
C language from basics to advanced placement prep
303 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 303 questions
Q.41 Easy Dynamic Memory
What does free() function do in C?
A Allocates memory from heap
B Deallocates previously allocated memory
C Copies memory from one location to another
D Initializes memory with zeros
Correct Answer:  B. Deallocates previously allocated memory
EXPLANATION

free() is used to deallocate memory that was previously allocated using malloc(), calloc(), or realloc().

Take Test
Q.42 Easy Dynamic Memory
Which header file must be included to use dynamic memory allocation functions in C?
A #include
B #include
C #include
D #include
Correct Answer:  A. #include
EXPLANATION

stdlib.h contains declarations for malloc(), calloc(), realloc(), and free() functions.

Take Test
Q.43 Easy Dynamic Memory
How much memory in bytes does calloc(10, 4) allocate?
A 10 bytes
B 4 bytes
C 40 bytes
D 10.4 bytes
Correct Answer:  C. 40 bytes
EXPLANATION

calloc(num, size) allocates num * size = 10 * 4 = 40 bytes total.

Take Test
Q.44 Easy Dynamic Memory
What is the return type of malloc()?
A void*
B int*
C char*
D NULL
Correct Answer:  A. void*
EXPLANATION

malloc() returns a generic pointer (void*) which can be cast to any data type pointer.

Take Test
Q.45 Easy Dynamic Memory
Which header file must be included for dynamic memory allocation functions in C?
A #include
B #include
C #include
D #include
Correct Answer:  A. #include
EXPLANATION

stdlib.h contains malloc(), calloc(), realloc(), and free() functions for dynamic memory management.

Take Test
Q.46 Easy Dynamic Memory
What is the correct way to allocate and initialize a structure dynamically?
struct Node { int data; int next; };
A struct Node *n = malloc(sizeof(struct Node)); n->data = 5;
B struct Node *n = (struct Node*)malloc(sizeof(struct Node)); n->data = 5;
C struct Node n = malloc(sizeof(struct Node));
D Both A and B are equally correct
Correct Answer:  D. Both A and B are equally correct
EXPLANATION

Both A and B allocate memory correctly; B includes explicit typecasting which is optional in C but good practice.

Take Test
Q.47 Easy Dynamic Memory
Which statement best describes dynamic memory allocation's advantage over static allocation?
A Dynamic memory is always faster
B Size is determined at compile time with dynamic allocation
C Memory size can be determined at runtime based on actual needs
D Dynamic memory never causes fragmentation
Correct Answer:  C. Memory size can be determined at runtime based on actual needs
EXPLANATION

Dynamic memory allows flexible sizing at runtime, which static arrays cannot provide.

Take Test
Q.48 Easy Dynamic Memory
What happens when you call free() on a NULL pointer?
A Program crashes
B It is safely ignored (no operation performed)
C It returns false
D Undefined behavior occurs
Correct Answer:  B. It is safely ignored (no operation performed)
EXPLANATION

According to C standard, free(NULL) is safe and does nothing.

Take Test
Q.49 Easy Dynamic Memory
What is the key difference between malloc() and calloc()?
A malloc() allocates memory; calloc() deallocates it
B calloc() initializes allocated memory to zero; malloc() does not
C malloc() is faster than calloc()
D calloc() allocates more memory than malloc()
Correct Answer:  B. calloc() initializes allocated memory to zero; malloc() does not
EXPLANATION

calloc() takes two parameters (count, size) and initializes memory to 0, while malloc() takes one parameter and leaves memory uninitialized.

Take Test
Q.50 Easy Dynamic Memory
Which header file must be included to use malloc(), calloc(), and free() functions?
A #include
B #include
C #include
D #include
Correct Answer:  B. #include
EXPLANATION

All memory allocation and deallocation functions are declared in <stdlib.h>.

Take Test
IGET
iget AI
Online · Ask anything about exams
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