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.
calloc() takes two parameters (number of elements, size) and initializes all bytes to zero, while malloc() leaves memory uninitialized.
Q.262Medium
What is the output of this code? int *p, *q; int x = 5; p = &x; q = p; printf("%d %d", *p, *q);
Answer: A
Both p and q point to the same variable x. Dereferencing both gives the value 5.
Q.263Medium
Which statement correctly declares a pointer to a pointer?
Answer: B
int **p declares a pointer to a pointer (double pointer). Each * adds one level of indirection.
Q.264Medium
What will be printed? int x = 100, y = 200; int *p = &x; int *q = &y; p = q; printf("%d", *p);
Answer: B
p is reassigned to point to y (p = q). Dereferencing p now gives the value of y, which is 200.
Q.265Medium
What is the primary disadvantage of using free() without proper checks?
Answer: B
Calling free() on already freed memory or using a pointer after freeing it causes double-free errors and use-after-free bugs, leading to undefined behavior.
Q.266Medium
What will be the output? char *str = "Hello"; printf("%c", *(str+1));
Answer: B
str points to 'H', str+1 points to 'e'. Dereferencing gives 'e'.
Q.267Medium
What is the output? void func(int *arr) { arr[0] = 100; } int main() { int a[5] = {1,2,3,4,5}; func(a); printf("%d", a[0]); }
Answer: B
Arrays are passed by reference (as pointers). Changes made in func() affect the original array. a[0] becomes 100.
Q.268Medium
Which of the following is valid pointer arithmetic in C?
Answer: A
Valid pointer arithmetic includes addition/subtraction with integers and subtraction between pointers. Multiplication, division, and pointer addition are invalid.
Q.269Medium
Which of the following correctly declares a pointer to a function that takes two integers and returns an integer?
Answer: A
int (*ptr)(int, int) declares a pointer to a function. int *ptr(int, int) declares a function returning pointer to int.
Q.270Medium
What happens when you try to modify a string literal through a pointer? char *str = "Hello"; str[0] = 'J';
Answer: B
String literals are stored in read-only memory. Attempting to modify causes undefined behavior or segmentation fault.
Q.271Medium
Consider the code: int *p = NULL; int *q = malloc(sizeof(int)); free(q); free(q); What is the issue here?
Answer: A
Freeing the same pointer twice causes double free error and undefined behavior. Should set q=NULL after first free.
Q.272Medium
What is the output? int a = 10; int *p = &a; int *q = p; q = NULL; printf("%d", *p);
Answer: A
q = NULL only changes q, not p. p still points to a, so *p prints 10.
Q.273Medium
Which pointer operation is NOT valid in C?
Answer: C
Pointer multiplication is not allowed. Valid operations are addition, subtraction, increment, decrement, and comparison.
Q.274Medium
What is the output? int arr[2][3] = {{1,2,3}, {4,5,6}}; int *p = (int*)arr; printf("%d", *(p+4));
Answer: A
Array flattened: 1,2,3,4,5,6. p+4 points to 5th element which is 5.
Q.275Medium
Which of the following is correct about pointer assignment? int *p, *q; p = q; // What happens?
Answer: B
p = q copies the address stored in q to p. Now both point to same location.
Q.276Medium
What is the output? int x = 5; int *const p = &x; x = 10; printf("%d", *p);
Answer: B
const pointer p cannot be changed, but x can be modified. *p prints current value of x which is 10.
Q.277Medium
What is the output? int arr[] = {10, 20, 30}; int *p = arr; printf("%d", sizeof(p));
Answer: B
p is a pointer, so sizeof(p) returns pointer size (8 bytes on 64-bit, 4 on 32-bit), not array size.
Q.278Medium
Consider the code: int x = 10; int *p = &x; int q = &p; What is the value of q?
Answer: A
q points to p, p points to x. **q dereferences twice: first gets p's value (address of x), second gets x's value (10).
Q.279Medium
Which operation is NOT allowed on void pointers in C without explicit casting?
Answer: B
Void pointers cannot perform pointer arithmetic (++, --, +n) directly. They must be cast to a specific type first.
Q.280Medium
What is the difference between NULL and a wild pointer?
Answer: A
NULL is explicitly set to address 0, while wild pointers contain garbage values from uninitialized memory.