Predict-the-output questions demand more than precedence: each answer follows from state changes, pointer movement, control flow and sequencing. Definition-led C MCQs ask what a construct means; output questions require either a complete execution trace or proof that the C standard guarantees no unique result. Before evaluating any line, write down the current values of its variables. Aim for repeatable reasoning, not quick mental simulation. Use the wider Coding & DSA hub for programming practice beyond output tracing.
1. C output questions need a trace, not a guess
Use the same four-pass method for every question:
Expand every macro by textual substitution.
Apply operator precedence, associativity and sequencing rules.
Draw arrays and pointers, including each pointer's current position.
Trace control flow one iteration or one function call at a time.
A useful trace records the step, expression, state before it, value produced and state after it.
Precedence and evaluation order are different ideas. Precedence groups operators into an expression tree, but it does not create a safe order for multiple unsequenced writes to the same scalar. Multiple unsequenced writes to the same scalar can make the behavior undefined even when precedence determines the expression tree.
Read each stem and its options, then follow the explanation rather than memorising the option letter. For NAT questions, write every intermediate value even though no options are supplied. The same trace-first habit also works well for the Data Structures MCQs collection on arrays, trees and graphs.
2. C macro and bitwise output questions, Questions 1 to 3
Question 1: macro arguments without protective parentheses
TCS 2024.
#include <stdio.h>
#define prod(a,b) a*b
int main(void) {
int x = 3, y = 4;
printf("%d", prod(x + 2, y - 1));
return 0;
}A.
10B.
20C.
15D.
0
Answer: option A, 10. The macro call expands textually to x+2*y-1, not to (x+2)*(y-1). Multiplication is evaluated first: 3 + 2*4 - 1 = 3 + 8 - 1 = 10. A safer definition would parenthesise both parameters and the complete replacement expression.
Question 2: SQR is still textual substitution
ISRO Computer Science 2014.
What is the output of the following C program? #include<stdio.h> #define SQR(x) (x*x) int main() { int a; int b=4; a=SQR(b+2); printf("%d\n",a); return 0; }A.
14B.
36C.
18D.
20
Answer: option A, 14. Substituting b+2 into both occurrences of x gives (b+2*b+2). With b = 4, multiplication happens first, so the value is 4 + 8 + 2 = 14, not (b+2)*(b+2).
Question 3: a bit test creates an alternating output
ISRO Computer Science 2015.
The for loop for (i=0; i<10; ++i) printf("%d", i&1); prints:A.
0101010101B.
0111111111C.
0000000000D.
1111111111
Answer: option A, 0101010101. For i = 0, 1, 2, 3, the values of i & 1 are 0, 1, 0, 1. Even integers have a low bit of 0, while odd integers have a low bit of 1, so ten iterations print five 01 pairs.
3. C assignment, increment and undefined-behaviour outputs, Questions 4 and 5
Question 4: update the stored value before reading it twice
IBPS 2024.
What will be the output of the following C code? #include<stdio.h> int main() { int a = 1; a += 3; printf("%d", a + a); return 0; }A.
4B.
6C.
8D.
10E.
2
Answer: option C, 8. The statement a += 3 changes the stored value from 1 to 4. The later expression therefore reads a twice as 4, giving 4 + 4 = 8; the old value does not remain in that expression.
Question 5: two unsequenced modifications mean no unique output
IBPS 2025.
What will be the output of the following C program? #include <stdio.h> int main() { int x = 10; printf("%d %d", x++, ++x); return 0; }A.
10 12B.
11 12C.
10 11D.
12 12E.
Undefined behavior
Answer: option E, Undefined behavior. Both function arguments modify x, and C does not sequence one argument evaluation before the other. Consequently, C guarantees no numeric output, even if a particular compiler appears consistent in one build.
4. C pointer increment and arithmetic outputs, Questions 6 to 8
Question 6: postfix ++ moves the pointer after dereferencing
UGC NET Computer Science, Paper 2 (August), 2024.
#include <stdio.h>
int main(void) {
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d", *p++);
printf("%d", *(p + 1));
return 0;
}A.
1, 2B.
1, 3C.
2, 3D.
1, 4
Answer: option B, values 1 and 3. Parse *p++ as *(p++): read arr[0] = 1, then move p to arr[1]. Now *(p+1) is arr[2] = 3; without a separator, the code prints 13, while the option records 1, 3.
Question 7: array indexing through an offset pointer
GATE Computer Science 2019.
Consider the following C program: #include <stdio.h> int main(){ int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4; printf("%d\n", ip[1]); return 0; } The number that will be displayed on execution of the program is ___________ .Answer: 6. With zero-based indexing, ip = arr + 4 points to arr[4], whose value is 5. The expression ip[1] means *(ip+1), which reaches arr[5] = 6.
Question 8: pointer subtraction counts elements, not bytes
GATE Computer Science, Set 2, 2024.
#include <stdio.h>
int main(void) {
double a[2] = {20.0, 25.0}, *p, *q;
p = a;
q = p + 1;
printf("%d,%d", (int)(q - p), (int)(*q - *p));
return 0;
}A.
4,8B.
1,5C.
8,5D.
1,8
Answer: option B, 1,5. With q at a[1] and p at a[0], q-p = 1 element, not the byte size of double. The value difference is 25.0 - 20.0 = 5.0, cast to 5.
5. C double pointers and pointer-parameter outputs, Questions 9 and 10
Question 9: incrementing a pointer-to-pointer changes the selected pointer
GATE Computer Science, Set 3, 2015.
#include <stdio.h>
int main(void) {
static int a[] = {10, 20, 30, 40, 50};
static int *p[] = {a, a + 3, a + 4, a + 1, a + 2};
int **ptr = p;
ptr++;
printf("%d%d", (int)(ptr - p), **ptr);
return 0;
}Answer: 140. Initially, ptr = &p[0]; after ptr++, it becomes &p[1], so ptr-p = 1. Because p[1] = a+3, **ptr = a[3] = 40, and %d%d concatenates 1 and 40 as 140.
![Pointer trace for Question 9 showing ptr advancing from p[0] to p[1], giving ptr-p of 1 and value 40, printed as 140.](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1784270221930_t54ql4.jpg)
Question 10: reassigning a pointer parameter does not reassign the caller's pointer
GATE Computer Science 2010.
#include <stdio.h>
void f(int *p, int *q) {
p = q;
*p = 2;
}
int i = 0, j = 1;
int main(void) {
f(&i, &j);
printf("%d %d\n", i, j);
return 0;
}A.
2 2B.
2 1C.
0 1D.
0 2
Answer: option D, 0 2. Function parameters p and q are local pointer copies. The assignment p=q makes local p point to j, so *p=2 changes j to 2, while i remains 0.
If these pointer-state traces were useful, Stacks and Queues: Operations and Uses applies the same way of thinking to array and pointer based implementations.
6. C loop, continue and short-circuit outputs, Questions 11 and 12
Question 11: continue does not cancel the for update
ISRO Computer Science 2011.
#include <stdio.h>
int main(void) {
int index;
for (index = 1; index <= 5; index++) {
printf("%d", index);
if (index == 3) continue;
}
return 0;
}A.
1245B.
12345C.
12245D.
12354
Answer: option B, 12345. Each value is printed before the if. At index == 3, continue moves to the for loop's update expression, so index++ still produces 4; there is no later body statement to skip.
Question 12: && decides whether i++ runs
GATE Computer Science, Set 1, 2021.
Consider the following C program. #include <stdio.h> int main() { int i, j, count; count = 0; i = 0; for (j = -3; j <= 3; j++) { if ((j >= 0) && (i++)) { count = count + j; } } count = count + i; printf("%d", count); return 0; }A.
The program will not compile successfully.B.
The program will compile successfully and output 10 when executed.C.
The program will compile successfully and output 8 when executed.D.
The program will compile successfully and output 13 when executed.
Answer: option B, output 10. For j = -3, -2, -1, the left side is false, so i++ does not run. For j = 0, 1, 2, 3, it produces 0, 1, 2, 3; only 1 + 2 + 3 enters count, giving 6, and final i = 4 makes count = 6 + 4 = 10.
7. Predict-the-output C practice: the short version and next step
Keep one checklist beside you: expand macros, parenthesise the parsed expression, mark every write to a variable, draw pointer positions, and trace one loop iteration at a time. Stop at "undefined behaviour" whenever C provides no guaranteed result. Reproduce each state trace before checking the answer.
For focused concepts, MCQs and coding questions, continue with C Language. Use Coding For Placements when you want C alongside other languages and placement-oriented practice. Solve first, then use the explanation to locate the step that changed the output.




