iGET

C Programming - MCQ Practice Questions

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

972 questions | 100% Free

Q.781Easy

What does calloc() do differently from malloc()?

Q.782Medium

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

Q.783Easy

Which function is used to free dynamically allocated memory?

Q.784Medium

What is a memory leak in C?

Q.785Medium

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

Q.786Medium

What is the purpose of realloc() function?

Q.787Medium

Which of the following is correct for dynamic array allocation?

Q.788Medium

What is double free error?

Q.789Medium

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

Q.790Medium

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

Q.791Hard

What will happen if malloc() fails and returns NULL but code doesn't check?

Q.792Hard

Which statement about dynamic memory is TRUE?

Q.793Hard

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; }

Q.794Hard

What is the correct way to allocate memory for 2D dynamic array (3x4)?

Q.795Hard

What does this realloc() call do? int *p = malloc(5 * sizeof(int)); p = realloc(p, 10 * sizeof(int));

Q.796Easy

How much memory is allocated by malloc(sizeof(int) * 10) on a 32-bit system where sizeof(int) = 4?

Q.797Easy

Which header file must be included to use malloc(), calloc(), and free() functions?

Q.798Easy

What is the key difference between malloc() and calloc()?

Q.799Medium

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

Q.800Medium

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