What will be the output of the following code?
int *ptr = malloc(sizeof(int));
if(ptr == NULL) printf("Failed");
else printf("Success");
What is a memory leak in C?
What happens when you try to access memory after calling free()?
What is the purpose of realloc() function?
Which of the following is correct for dynamic array allocation?
Advertisement
What is double free error?
Analyze this code:
char *str = malloc(5);
strcpy(str, "Hello");
How many bytes should malloc allocate for safety?
What is the output?
int *p = malloc(sizeof(int) * 3);
p[0] = 1; p[1] = 2; p[2] = 3;
printf("%d", *(p+2));
Which of the following correctly allocates memory for an array of 5 strings (each max 20 characters)?
What is the purpose of typecasting in malloc()?
int *p = (int*)malloc(sizeof(int));
Analyze the memory leak in this code:
void func() {
int *p = malloc(100);
if(condition) return;
free(p);
}
What is the output of this code?
int *p = calloc(3, sizeof(int));
printf("%d %d %d", p[0], p[1], p[2]);
Consider reallocating memory:
int *p = malloc(10);
p = realloc(p, 20);
Which allocation method is most suitable for a dynamically growing linked list?
How can you safely check if malloc() succeeded?
In the context of dynamic memory, what does 'memory fragmentation' refer to?
What will happen if you try to allocate extremely large memory?
int *p = malloc(INT_MAX);
Which best practice prevents memory leaks in complex programs?
What does realloc() do if the new size is smaller than the old size?
What will be the output of this code?
int *p = (int*)malloc(5 * sizeof(int));
printf("%d", sizeof(p));