Top 20 MCQs — trace the output of loops, arrays, pointers, and recursion. Core to every 2026 tech placement test!
What is the output of the following code? int x = 5; while (x > 0) { printf("%d ", x); x -= 2; }
What does this code print? for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) printf("1 "); else printf("0 "); } }
Find the output: int arr[] = {1, 2, 3, 4, 5}; int sum = 0; for (int i = 0; i < 5; i += 2) sum += arr[i]; printf("%d", sum);
What is the output? int fact(int n) { if (n == 0) return 1; return n * fact(n - 1); } printf("%d", fact(4));
What does this print? int x = 10; int y = x++; printf("%d %d", x, y);
What is the output of this snippet? int a = 2, b = 3; a = a + b; b = a - b; a = a - b; printf("%d %d", a, b);
How many times does 'Hello' print? int i = 1; while (i <= 16) { printf("Hello "); i *= 2; }
What is the output? int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); } printf("%d", fib(6));
What does this print? int arr[] = {10, 20, 30, 40, 50}; int *ptr = arr; ptr += 2; printf("%d", *ptr);
Find the output: int x = 5; switch(x) { case 4: printf("Four"); case 5: printf("Five"); case 6: printf("Six"); default: printf("Other"); }
What is printed? for (int i = 0; i < 5; i++) { if (i % 2 == 0) continue; printf("%d ", i); }
What is the output? int count = 0; for (int i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 == 0) count++; } printf("%d", count);
What value does this function return for input 12? int mystery(int n) { int result = 0; while (n > 0) { result += n % 10; n /= 10; } return result; }
What is the output? int arr[5] = {0}; for (int i = 0; i < 5; i++) arr[i] = i * i; printf("%d", arr[3]);
What does this recursive function return for reverseNum(1234)? int reverseNum(int n, int rev = 0) { if (n == 0) return rev; return reverseNum(n / 10, rev * 10 + n % 10); }
What is the output? int i = 0; do { printf("%d ", i); i++; } while (i < 0);
What is the final value of 'result'? int result = 0; for (int i = 1; i <= 5; i++) result = result * 10 + i; printf("%d", result);
What prints here? void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int x = 7, y = 3; swap(&x, &y); printf("%d %d", x, y);
What is the output? int n = 8; int count = 0; while (n) { count += n & 1; n >>= 1; } printf("%d", count);
What is the output of this code? int a = 3, b = 4, c = 0; c = (a > b) ? a : b; printf("%d", c);
Other Technical Topics: