TCS NQT Programming Logic Questions With Answers: C Pragramming 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

TCS NQT Programming Logic Questions

with Answers
C Pragramming
1. What will be returned in the following C code?

a) number of characters equal in sc


b) length of string s
c) doesn’t return any value
d) displays string s https://www.freshersnow.com/placement-papers-download/

Answer: b
Explanation: The strlen() function is used to return the length of the string s.

2.  The C code ‘for(;;)’ represents an infinite loop. It can be terminated by


___________
a) break
b) exit(0)
c) abort()
d) terminate

Answer: a

CPP
3. What will be the output of the following C++ code?
a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error https://www.freshersnow.com/placement-papers-download/

Answer: b
Explanation: a[1][2] means 1 * (4)+2 = 6th element of an array starting from zero.
Output:

4. What are the advantages of passing arguments by reference?


a) Changes to parameter values within the function also affect the original
arguments
b) There is need to copy parameter values (i.e. less memory used)
c) There is no need to call constructors for parameters (i.e. faster)
d) All of the mentioned

Answer: d
Explanation: All the above mentioned are advantages and properties of call by
reference.

Java
5. What will s2 contain after following lines of Java code?
a) one
b) two
c) onetwo
d) twoone

Answer: c
Explanation: Two strings can be concatenated by using append() method.

6. Thread priority in Java is?


a) Integer
b) Float
c) double
d) long

Answer: a
Explanation: Java assigns to each thread a priority that determines hoe that
thread should be treated with respect to others. Thread priority is integers that
specify relative priority of one thread to another.

Data Structures
7. Which node is the child node of the Node D in the following ternary tree?

a) A
b) C
c) B
d) No child node

Answer: d
Explanation: Since Node D is the Leaf node of the above ternary tree and leaf
node has no child node. So there is no child node for Node D in the above
ternary tree.

8.  While evaluating a prefix expression, the string is read from?


a) left to right
b) right to left
c) center to right
d) center to left to right

Answer: b
Explanation: The string is read from right to left because a prefix string has
operands to its right side.

CPP
9. Which is used to describe the function using placeholder types?
a) template parameters
b) template type parameters
c) template type
d) type parameters

Answer: b
Explanation: During runtime, We can choose the appropriate type for the function
and it is called as template type parameters.

10. What will be the output of the following C++ code?


a) 0
b) 5
c) This value of b will make the product zero. So please provide positive values.
d) Product of 5 and 0 is: 0

Answer: c
Explanation: As the value of b = 0 is provided to the func() and the function is throwing
an exception whenever the value of b = 0. Therefore the function throws the exception
which will be printed on the screen.
Output:

You might also like