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

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

Q.22Medium

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

Q.23Easy

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

Q.24Easy

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

Q.25Medium

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

Q.26Medium

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

Q.27Hard

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

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

Q.29Hard

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

Q.30Medium

How can you safely check if malloc() succeeded?

Q.31Medium

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

Q.32Medium

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

Q.33Medium

Which best practice prevents memory leaks in complex programs?

Q.34Easy

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

Q.35Easy

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

Q.36Easy

What is the return type of malloc()?

Q.37Medium

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

Q.38Medium

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

Q.39Medium

Which statement about free() is correct?

Q.40Medium

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