iGET

C Programming - MCQ Practice Questions

Practice free C Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

978 questions | 100% Free

Q.1Medium

What will be the output of the following code? int *ptr = malloc(sizeof(int)); if(ptr == NULL) printf("Failed"); else printf("Success");

Q.2Medium

What is a memory leak in C?

Q.3Medium

What happens when you try to access memory after calling free()?

Q.4Medium

What is the purpose of realloc() function?

Q.5Medium

Which of the following is correct for dynamic array allocation?

Q.6Medium

What is double free error?

Q.7Medium

Analyze this code: char *str = malloc(5); strcpy(str, "Hello"); How many bytes should malloc allocate for safety?

Q.8Medium

What is the output? int *p = malloc(sizeof(int) * 3); p[0] = 1; p[1] = 2; p[2] = 3; printf("%d", *(p+2));

Q.9Medium

Which of the following correctly allocates memory for an array of 5 strings (each max 20 characters)?

Q.10Medium

What is the purpose of typecasting in malloc()? int *p = (int*)malloc(sizeof(int));

Q.11Medium

Analyze the memory leak in this code: void func() { int *p = malloc(100); if(condition) return; free(p); }

Q.12Medium

What is the output of this code? int *p = calloc(3, sizeof(int)); printf("%d %d %d", p[0], p[1], p[2]);

Q.13Medium

Consider reallocating memory: int *p = malloc(10); p = realloc(p, 20);

Q.14Medium

Which allocation method is most suitable for a dynamically growing linked list?

Q.15Medium

How can you safely check if malloc() succeeded?

Q.16Medium

In the context of dynamic memory, what does 'memory fragmentation' refer to?

Q.17Medium

What will happen if you try to allocate extremely large memory? int *p = malloc(INT_MAX);

Q.18Medium

Which best practice prevents memory leaks in complex programs?

Q.19Medium

What does realloc() do if the new size is smaller than the old size?

Q.20Medium

What will be the output of this code? int *p = (int*)malloc(5 * sizeof(int)); printf("%d", sizeof(p));