c2cedge
C, Java & Python · E — Cross-Language & Practice

Output Prediction & Tricky Questions

MCQ rounds are full of 'what does this print?'. A calm, systematic reading — language, types, operators, mutation, scope — turns traps into easy marks.

Test weight: Very highSkill: Reading code exactlyDifficulty: Medium–Hard

Screening tests lean heavily on output-prediction MCQs because they reveal whether you truly read code or just recognise it. The good news: almost all of them reuse a small set of language-specific gotchas you've already met. The skill is a calm, systematic read rather than a guess.

A checklist for any 'what prints?' question

Run through five things in order: (1) which language are the rules from? (2) the operand types (int vs float, value vs reference)? (3) the exact operator behaviour (division, increment, precedence)? (4) any mutation/aliasing of shared objects? (5) scope and binding (closures, defaults).

Four classic gotchas
# Python: mutable default argument
def add(x, lst=[]): lst.append(x); return lst
print(add(1)); print(add(2))   # [1]  then  [1, 2]  (shared!)

// Java: == vs equals
String a = new String("x"), b = new String("x");
System.out.println(a == b);     // false (different objects)

/* C */ printf("%d", 5 / 2);    // 2  (integer division)
# Python: print(5 / 2)          # 2.5 (true division)
⚡ The edge
  • Most output traps are one of a handful you've seen: integer vs true division, post/pre increment, == vs equals / is, string immutability, mutable defaults, and aliasing. Recognise the family and you have the answer.
  • Read types and mutation, not just syntax. The same line behaves differently depending on whether operands are ints or floats, and whether an object is shared — slow down and track both.
Worked example
Predict the output: (Python) a=[1,2]; b=a; b.append(3); print(a)
  1. b = a does not copy the list; both names refer to the same list object (aliasing).
  2. b.append(3) mutates that shared list in place.
  3. So printing a shows the change too: [1, 2, 3].
Worked example
Predict the output: (Java) int i = 1; System.out.println(i++ + ++i);
  1. i++ uses the current value 1, then i becomes 2 (post-increment).
  2. ++i increments i to 3 first, then uses 3 (pre-increment).
  3. So the sum is 1 + 3 = 4 (and i ends at 3). Unlike C, Java defines this evaluation order.
⚠ Watch out
  • Integer vs true division (5/2): 2 in C/Java, 2.5 in Python.
  • == vs equals / is: comparing references vs content (Java), identity vs value (Python).
  • Mutable defaults and aliasing in Python; string immutability everywhere it applies.
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms