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

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

Q.802Easy

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

Q.803Easy

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

Q.804Medium

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

Q.805Medium

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

Q.806Hard

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

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

Q.808Hard

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

Q.809Medium

How can you safely check if malloc() succeeded?

Q.810Medium

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

Q.811Medium

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

Q.812Medium

Which best practice prevents memory leaks in complex programs?

Q.813Easy

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

Q.814Easy

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

Q.815Easy

What is the return type of malloc()?

Q.816Medium

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

Q.817Medium

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

Q.818Medium

Which statement about free() is correct?

Q.819Medium

In dynamic 2D array creation: int arr = (int)malloc(m * sizeof(int*)); what does the first malloc() allocate?

Q.820Medium

What happens if you use a pointer after calling free() on it (without reallocating)?