TCS Ninja Interview — C Output Prediction and Pointer Debugging
- Field
- Engineering
- Company
- Tata Consultancy Services
- Role
- Assistant System Engineer Trainee (Ninja)
- Duration
- 20 min
- Difficulty
- Medium
- Completions
- New
- Updated
- 2026-06-11
How to prepare
What this round tests, what strong and weak answers sound like, and the traps to sidestep.
What this round is about
- Topic focus. You trace short C snippets line by line and state the exact printed output, covering increment operators, pointer arithmetic, storage classes, sizeof, and undefined behaviour.
- Conversation dynamic. The interviewer shows one snippet at a time, makes you finish the trace, then adds a twist like fix the bug or why is this undefined behaviour.
- What gets tested. Whether you read C the way the compiler does, reasoning about precedence and memory rather than guessing a single number.
- Round format. A voice plus whiteboard round where you draw the stack and the memory boxes as you trace each value.
What strong answers look like
- Running trace on the board. You write the variables as boxes and update them each line, for example showing num1 taking num2 before num2 is incremented.
- Precedence stated out loud. You say postfix increment binds tighter than prefix and that star ptr plus plus is star of ptr plus plus evaluated right to left, then compute.
- Honest undefined behaviour. You name a freed or uninitialised pointer as a dangling or wild pointer and call the result undefined rather than inventing a clean output.
- Memory model named. You distinguish sizeof of an array from sizeof of a pointer and say what changes on a 64-bit machine.
What weak answers look like (and how to avoid them)
- Single guessed number. Blurting an output with no trace reads as hand-waving, so narrate each line instead.
- Left-to-right pointer read. Reading star ptr plus plus as a pre-increment of the pointed value is wrong, so apply right-to-left associativity.
- Clean output for a bad pointer. Predicting a tidy value for a freed or uninitialised pointer fails, so call it undefined behaviour.
- sizeof confusion. Giving the pointer size for a whole array is a classic miss, so state what sizeof measures on each.
Pre-interview checklist (2 minutes before you start)
- Recall increment precedence. Postfix binds tighter than prefix, and prefix and dereference share precedence with right-to-left associativity.
- Have pointer fundamentals ready. A pointer holds an address, a null pointer is value zero, and calloc zero-initialises the block.
- Identify dangling-pointer causes. Free, a returned non-static local address, or a variable going out of scope all create one.
- Pull up your sizeof facts. Array size is element size times count; pointer size depends on the machine, typically eight bytes on 64-bit.
- Think of the storage classes. Be ready to say what a static variable prints across repeated calls versus an auto variable.
How the AI behaves
- Probes every trace. It asks why an operator binds first or why a value is what you said, not just for the final number.
- No mid-interview praise. It will not say great answer; it acknowledges the specific line you traced and pushes on.
- Interrupts on a guess. If you state output with no trace, it slows you down and makes you trace one line at a time.
- One snippet at a time. It finishes each trace and its twist before moving to the next card.
Common traps in this type of round
- Output without a trace. Stating a number and stopping, with no line-by-line reasoning to back it.
- Precedence inversion. Evaluating star ptr plus plus or a mixed pre and post increment expression in the wrong order.
- Undefined behaviour as defined. Treating modification of a variable more than once between sequence points as having one guaranteed value.
- Dangling pointer denied. Saying a returned local-variable address is safe instead of naming the dangling pointer.
- Resume bluff. Listing C as a strength but not knowing what calloc returns or what a null pointer is.
- sizeof on arrays versus pointers. Reporting the pointer size for an array passed into a function as if it were the full array.
Sample problems you'll face
The 2 problems below are the same ones you'll work through in the live session — no surprises. Read the constraints carefully; the AI persona will refer you to the on-canvas card by problem number.
- 1Predict the Output: Pointer Walk Over a String Literal
char *ptr = "Linux"; printf("[%c]", *ptr++); printf("[%c]", *ptr); Trace this snippet. State which character each printf sends to the screen and where ptr points after the first line. The interviewer will then ask why the evaluation goes in the direction it does, and what would change if the second line were plus plus star ptr instead.
Example inputchar *ptr = "Linux";Example output[L][i]- star ptr plus plus is parsed as star of (ptr plus plus): since dereference and postfix increment are involved, the postfix increment binds to ptr and yields the old pointer, which is then dereferenced.
- The first printf therefore reads the original first byte (capital L) and the post-increment advances ptr to point at the second byte; the second printf reads lowercase i.
- A string literal is read-only storage, so writing through ptr would be undefined behaviour even though reading is fine.
- ON THE CANVAS: draw the bytes of Linux as boxes with their addresses, place ptr as an arrow on the first box, then move the arrow after the first printf and write the character each printf prints before you say done.
- 2Find the Bug: Function Returning a Local Array
int *makeArray(void) { int arr[3] = {10, 20, 30}; return arr; } /* main calls int *p = makeArray(); then prints p[0], p[1], p[2] */ Trace what main attempts to print, then debug it. State whether the storage at that address is still valid after makeArray returns, name the defect precisely, and propose a fix that makes the behaviour defined without changing what main expects.
Example inputint *p = makeArray(); printf("%d %d %d", p[0], p[1], p[2]);Example outputUndefined behaviour (dangling pointer; may print garbage or crash)- arr is a non-static local array; its storage lives in makeArray's stack frame and is released the instant the function returns, so the returned pointer is a dangling pointer.
- Reading through that pointer in main is undefined behaviour: it may appear to print 10 20 30, may print garbage, or may cause a segmentation fault, and the result is not guaranteed by the language.
- Two correct fixes: declare the array static int arr[3] so it has program lifetime, or allocate with malloc inside makeArray and have the caller free it; do not just change the printed values.
- ON THE CANVAS: draw makeArray's stack frame with arr inside it, draw the returned pointer, then cross out the frame at the return and state in words why the address in main is no longer backed by valid storage before you give the fix.
The full breakdown
How you're scored, the questions candidates ask most, and the research this interview is built on. Skim it — or just start the interview.
Interview framework
You will be scored on these 5 dimensions. The full rubric with definitions is below.
What we evaluate
Your final scorecard breaks down across these dimensions. The full rubric and tier criteria are revealed inside the interview itself.
- Line-By-Line Trace Discipline20%
- Precedence and Associativity Reasoning18%
- Pointer and Memory Model18%
- Undefined Behaviour Honesty18%
- Debug and Fix Fluency14%
- Core C Fundamentals Recall12%
Common questions
Sources this interview is built on
Real candidate-report URLs (Glassdoor / AmbitionBox / PrepInsta / GeeksforGeeks / Medium) reviewed when authoring the questions, persona, and rubric. Verify the realism yourself.
- Output of C programs Set 39 (Pre Increment and Post Increment) - GeeksforGeeksgeeksforgeeks.org
- Operator Precedence and Associativity in C - GeeksforGeeksgeeksforgeeks.org
- Dangling, Void, Null and Wild Pointers in C - GeeksforGeeksgeeksforgeeks.org
- TCS Ninja Recruitment Process 2026 for Freshers - PrepInstaprepinsta.com
- TCS NQT interview experience for the NINJA ROLE - GeeksforGeeksgeeksforgeeks.org