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.801Medium

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

Q.802Medium

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

Q.803Medium

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

Q.804Easy

What happens when you call free() on a NULL pointer?

Q.805Easy

Which statement best describes dynamic memory allocation's advantage over static allocation?

Q.806Medium

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

Q.807Medium

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

Q.808Hard

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

Q.809Medium

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

Q.810Hard

What is the risk in this code? char *str = malloc(5); strcpy(str, "Hello World");

Q.811Medium

How can you safely check if malloc() succeeded?

Q.812Medium

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

Q.813Medium

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

Q.814Medium

Which best practice prevents memory leaks in complex programs?

Q.815Easy

What is the correct way to allocate and initialize a structure dynamically? struct Node { int data; int next; };

Q.816Easy

Which header file must be included for dynamic memory allocation functions in C?

Q.817Easy

What is the return type of malloc()?

Q.818Medium

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

Q.819Medium

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

Q.820Medium

Which statement about free() is correct?