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

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

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

Q.163Hard

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

Q.164Hard

What distinguishes a dangling pointer?

Q.165Hard

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

Q.166Hard

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

Q.167Hard

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

Q.168Hard

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

Q.169Hard

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

Q.170Hard

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

Q.171Hard

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

Q.172Hard

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

Q.173Hard

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

Q.174Hard

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

Q.175Hard

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

Q.176Hard

Which statement about #define is TRUE?

Q.177Hard

What is the problem with this macro? #define DOUBLE(x) x*x int result = DOUBLE(2+3);

Q.178Hard

What will be the output? #define MIN(a,b) ((a)<(b)?(a):(b)) int x=5; int y=10; int z = MIN(x++, y++);

Q.179Hard

What is the difference between #if and #ifdef?

Q.180Hard

What preprocessor features should be avoided for safer code?