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?
Advertisement
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?
Which statement about #define is TRUE?
What is the problem with this macro?
#define DOUBLE(x) x*x
int result = DOUBLE(2+3);
What will be the output?
#define MIN(a,b) ((a)<(b)?(a):(b))
int x=5; int y=10;
int z = MIN(x++, y++);
What is the difference between #if and #ifdef?
What preprocessor features should be avoided for safer code?