TCS NQT Programming Logic Questions and Answers
TCS NQT Programming Logic Questions and Answers
and Answers
C Programming
1. What will be the output of the following C code?
a) Compilation error
b) Undefined behaviour
c) Whatever user types
d) None of the mentioned
Answer: c
2. What will be the output of the following C code if the current system date is
6/22/2017?
a) 8
b) 7
c) 5
d) 6
Answer: b
Explanation: Since the given date is 22nd of June, 2017. Since June is the sixth
month of the year, the output will be 5. (0-Jan, 1-Feb, 2-March, 4-April, 5-May,
6-June……..) https://www.freshersnow.com/placement-papers-download/
Answer: b
CPP
Answer: b
Explanation: In this program, We are overloading the function and getting the
output as 10 and 2.5 by division and multiplication.
Output:
Answer: b
Explanation: As the return type of function is void therefore function is not
returning anything. Now as the function is taking a template T as its argument
which is a general type, therefore, it is accepting a single general type argument.
Java
6. In the following Java code, which code fragment should be inserted at line 3 so
that the output will be: “123abc 123abc”?
a) sb1.append(“abc”); s1.append(“abc”);
b) sb1.append(“abc”); s1.concat(“abc”);
c) sb1.concat(“abc”); s1.append(“abc”);
d) sb1.append(“abc”); s1 = s1.concat(“abc”);
Answer: d
Explanation: append() is stringbuffer method and concat is String class method.
append() is stringbuffer method and concat is String class method.
a) 0
b) 3
c) 3.0
d) 3.1
Answer: b
Data Structures
a) O(logn)
b) O(n)
c) O(1)
d) O(nlogn)
Answer: b
Explanation: All the characters in the string have to be processed, hence the
complexity is O(n).
9. What is a time complexity for inserting an alphabet in the tree using hash maps?
a) O (log n!)
b) O (n!)
c) O (n2)
d) O (1)
Answer: d
Explanation: Suffix tree is also known as PAT tree or position tree. It allows fast
string operation. Total time taken for construction of suffix tree is linear to the
length of the tree. The time complexity for inserting an alphabet in the tree using
hash maps is constant, O (1).
CPP
Answer: c
Explanation: In this program, We are using set_terminate to abort the program.
Output: