TCS Sample Coding Questions – given by TCS

TCS Sample Coding Questions – given by TCS

The following information has been shared by TCS.

rn

The TCS test for 2017-2018 campus seasons will have four sections:

rn

1) Section-1 Quantitative Test

rn

2) Section-2 Verbal Test (Test on Written English skills)

rn

3) Section-3 Test on Programming Language Proficiency (based on ‘C’)

rn

4) Section-4 Coding test (C Language)

rn

While practice tests for Section-1 and 2 are available in TCS Campus Commune portal in “Open Seesame”, Sections 3 & 4 are new sections and we have not been able to incorporate the same into ‘Open Seesame’ yet.

rn

Hence attaching a few sample questions from Sections 3 & 4 so that students who are TCS aspirants can start practicing in these lines.

rn

Section 3: C Language concepts

rn

Q1: What is the output of this C code?

rn

#include <stdio.h>

rn

void main()

rn

{

rn

int k = 5;

rn

int *p = &k;

rn

int **m = &p;

rn

printf(“%d%d%dn”, k, *p, **p);

rn

}

rn

 

rn

a) 5 5 5

rn

b) 5 5 junk

rn

c) 5 junk junk

rn

d) Compile time error

rn

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

rn

a) They both are the same

rn

b) Run time errors are automatically displayed in stderr

rn

c) Both are connected to the screen by default.

rn

d) stdout is line buffered but stderr is unbuffered.

rn

Q3: Given the below statements about C programming language;

rn

1) main() function should always be the first function present in a C program file

rn

2) all the elements of an union share their memory location

rn

3) A void pointer can hold address of any type and can be typcasted to any type

rn

4) A static variable hold random junk value if it is not initialised

rn

Which of the above are correct statements?

rn

A) 2,3

rn

B) 1,2

rn

C) 1,2,3

rn

D) 1,2,3,4

rn

 Q4 If a function is defined as static, it means

rn

A) The value returned by the function does not change

rn

B) all the variable declared inside the function automatically will be assigned initial value of zero

rn

C) It should be called only within the same source code / program file.

rn

D) None of the other choices as it is wrong to add static prefix to a function

rn

Q5: Comment on the below while statement

rn

while (0 == 0) { }      

rn

A) It has syntax error as there are no statements within braces {}

rn

B) It will run forever

rn

C) It compares 0 with 0 and since they are equal it will exit the loop immediately

rn

D) It has syntax error as the same number is being compared with itself

rn

 Section 4 Coding

rn

Q1 : Write a C program to calculate the factorial of a non-negative integer N. The factorial of a number N is defined as the product of all integers from 1 up to N. Factorial of 0 is defined to be 1. The number N is a non-negative integer that will be passed to the program as the first command line parameter. Write the output to stdout formatted as an integer WITHOUT any other additional text. You may assume that the input integer will be such that the output will not exceed the largest possible integer that can be stored in an int type variable.

rn

Q2: Write a C program to find the area of a triangle given the base and the corresponding height. The values base and height are both positive integers passed to the program as the first and second command line parameters respectively. Write the output to stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision WITHOUT any other additional text. Scientific format(such as 1.00E+5) should NOT be used while printing the output. You may assume that the inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

rn

FACE Prep has a comprehensive course for your complete Aptitude Preparation and TCS preparation.

Check out our Aptitude Course here.

Check out our TCS Course here.

c