TCS Sample Coding Questions: Official Practice Problems

TCS Sample Coding Questions: Official Practice Problems

TCS Sample Coding Questions: Official Practice Problems

Are you preparing for the TCS Campus Placement Exam? Understanding the exam pattern, important topics, and coding challenges will help you ace the test.

This guide provides an updated overview of the TCS written test format, along with sample questions for C programming concepts and coding tests.

TCS Written Test Structure – 2025

The TCS recruitment test consists of four sections:

SectionDescription
1. Quantitative AptitudeMathematical reasoning and problem-solving
2. Verbal AbilityEnglish proficiency, grammar, and written communication
3. Programming Language ProficiencyConceptual questions on C programming
4. Coding TestHands-on coding challenges in C language
  • Practice Tests for Sections 1 & 2 are available on the TCS Campus Commune Portal (Open Sesame).
  • Sections 3 & 4 are new, and sample questions are provided below.

Section 1: C Language Concepts – Sample Questions

Q1: What is the output of this C code?

#include <stdio.h>

void main() {
int k = 5;
int *p = &k;
int **m = &p;

printf("%d%d%d\n", k, *p, **m);
}

Options:
a) 5 5 5
b) 5 5 junk
c) 5 junk junk
d) Compile-time error

Q2: Which of the following statements about stdout and stderr are true?

a) They both are the same
b) Runtime errors are automatically displayed in stderr
c) Both are connected to the screen by default
d) stdout is line buffered, but stderr is unbuffered

Q3: Identify the correct statements about C programming:

  1. main() function should always be the first function in a C program
  2. All elements of a union share the same memory location
  3. A void pointer can store the address of any type and be typecasted
  4. A static variable holds a random junk value if not initialized

Options:
a) 2, 3
b) 1, 2
c) 1, 2, 3
d) 1, 2, 3, 4

Q4: If a function is defined as static, what does it mean?

a) The return value remains unchanged
b) All local variables inside the function are initialized to zero
c) The function can only be accessed within the same source file
d) Static prefix cannot be used with functions

Q5: What is the behavior of this while loop?

while (0 == 0) { } 

Options:
a) Syntax error (empty braces {})
b) Infinite loop
c) Exits immediately since 0 == 0
d) Syntax error (same number being compared)


Section 2: Coding Test – Sample Problems

Q1: Factorial Calculation

Problem:
Write a C program to calculate the factorial of a non-negative integer (N).

Input:

  • A single integer N (passed as a command-line argument).

Output:

  • A single integer representing N! (N factorial) without additional text.

Example:
Input: 5
Output: 120

Q2: Triangle Area Calculation

Problem:
Write a C program to find the area of a triangle given the base and height as input parameters.

Input:

  • Two positive integers representing the base and height (passed as command-line arguments).

Output:

  • A floating-point number rounded to two decimal places.

Example:
Input: 10 5
Output: 25.00

Note: Ensure the output is not printed in scientific notation (e.g., 1.00E+5 is incorrect).

Conclusion

The TCS Campus Placement Test is a crucial step for aspiring candidates looking to secure a job in one of the top IT companies. With a structured approach and focused preparation, you can excel in all four sections: Quantitative Aptitude, Verbal Ability, C Programming Concepts, and Coding Tests.

TCS Sample Coding Questions: Official Practice Problems