iGET

C Programming - MCQ Practice Questions

C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.

972 questions | 100% Free

Q.1Hard

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

Q.2Hard

Which statement about dynamic memory is TRUE?

Q.3Hard

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.4Hard

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

Q.5Hard

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

Q.6Hard

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.7Hard

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

Q.8Hard

Consider this code:
int *p = malloc(sizeof(int));
int *q = p;
free(p);
q[0] = 5; // What is the result?

Q.9Hard

What distinguishes a dangling pointer?

Q.10Hard

For a program handling 10^6 integers dynamically, which allocation is most appropriate?

Q.11Hard

What is the typical behavior if malloc() is called in a loop without corresponding free() calls?

Q.12Hard

What is a potential issue when allocating very large contiguous blocks (>10^8 bytes) dynamically?

Q.13Hard

Consider this: char *p = malloc(10); strcpy(p, "Hello World"); What occurs?

Q.14Hard

For implementing a dynamic stack in competitive programming, which memory management approach is best?

Q.15Hard

In a dynamic stack implementation for competitive programming, how should you handle reallocation when the stack becomes full?

Q.16Hard

Which of these represents proper error handling for malloc in competitive programming?

Q.17Hard

For a dynamic hash table with chaining, if collision occurs, the new element should be inserted where?

Q.18Hard

What is the memory overhead when allocating 1000 integers vs 1 integer in a system with malloc metadata?

Q.19Hard

In competitive coding, when implementing dynamic trees, which traversal is most suitable for level-order?

Q.20Hard

Which memory allocation technique provides better locality of reference for accessing array elements?