What will happen if malloc() fails and returns NULL but code doesn't check?
Which statement about dynamic memory is TRUE?
What is the issue in this code?
void func() {
int *p = malloc(sizeof(int));
*p = 5;
}
int main() {
func();
// p is not accessible here
return 0;
}
What is the correct way to allocate memory for 2D dynamic array (3x4)?
What does this realloc() call do?
int *p = malloc(5 * sizeof(int));
p = realloc(p, 10 * sizeof(int));
Advertisement
What is a common mistake in this code?
void func() {
int *ptr;
ptr = malloc(sizeof(int) * 5);
func2(ptr);
free(ptr);
}
void func2(int *p) {
free(p);
}
What is the risk in this code?
char *str = malloc(5);
strcpy(str, "Hello World");
Consider this code:
int *p = malloc(sizeof(int));
int *q = p;
free(p);
q[0] = 5; // What is the result?
What distinguishes a dangling pointer?
For a program handling 10^6 integers dynamically, which allocation is most appropriate?
What is the typical behavior if malloc() is called in a loop without corresponding free() calls?
What is a potential issue when allocating very large contiguous blocks (>10^8 bytes) dynamically?
Consider this: char *p = malloc(10); strcpy(p, "Hello World"); What occurs?
For implementing a dynamic stack in competitive programming, which memory management approach is best?
In a dynamic stack implementation for competitive programming, how should you handle reallocation when the stack becomes full?
Which of these represents proper error handling for malloc in competitive programming?
For a dynamic hash table with chaining, if collision occurs, the new element should be inserted where?
What is the memory overhead when allocating 1000 integers vs 1 integer in a system with malloc metadata?
In competitive coding, when implementing dynamic trees, which traversal is most suitable for level-order?
Which memory allocation technique provides better locality of reference for accessing array elements?