0% found this document useful (0 votes)
164 views

TCS NQT Programming Language Logic Q&A

This document contains 10 multiple choice questions about programming languages like C, C++, Java and data structures. The questions cover topics like file opening syntax in C, advantages of pass by reference in C++, output of Java code samples using stacks and queues, traversing binary trees, and functions on linked lists. The answers provided explain the concepts in the questions around file I/O, parameter passing, data structure operations and functions.

Uploaded by

Samkit Sanghvi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

TCS NQT Programming Language Logic Q&A

This document contains 10 multiple choice questions about programming languages like C, C++, Java and data structures. The questions cover topics like file opening syntax in C, advantages of pass by reference in C++, output of Java code samples using stacks and queues, traversing binary trees, and functions on linked lists. The answers provided explain the concepts in the questions around file I/O, parameter passing, data structure operations and functions.

Uploaded by

Samkit Sanghvi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

TCS NQT Programming Language Logic

Q&A
C Programming

1. Which one of the following is correct syntax for opening a file.


a) FILE *fopen(const *filename, const char *mode)
b) FILE *fopen(const *filename)
c) FILE *open(const *filename, const char *mode)
d) FILE open(const*filename)

Answer: a
Explanation: fopen() opens the named file, and returns a stream, or NULL of the
attempt fails.

2. What will be the output of the following C code?

a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
https://www.freshersnow.com/placement-papers-download/

Answer: c
CPP
3. 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.

4. Which header file is required to use any container?


a) <any>
b) <stl>
c) <container-any>
d) <containers>

Answer: a
Explanation: <any> header file is required to use any container and its realted
functions.

Java

5. What will be the output of the following Java code?


a) [3, 5]
b) [3, 2]
c) [3, 2, 5]
d) [3, 5, 2]

Answer: a
Explanation: push() and pop() are standard functions of the class stack, push()
inserts in the stack and pop removes from the stack. 3 & 2 are inserted using
push() the pop() is used which removes 2 from the stack then again push is used
to insert 5 hence stack contains elements 3 & 5.
Output:

6. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not


defined?
a) Integer.MAX_VALUE
b) BigDecimal.MAX_VALUE
c) 99999999
d) Integer.INFINITY https://www.freshersnow.com/placement-papers-download/

Answer: a
Explanation: A BlockingQueue without any intrinsic capacity constraints always
reports a remaining capacity of Integer.MAX_VALUE.
Data Structures
7. What will be result if the given stack is popped?

a) pat
b) tap
c) atp
d) apt

Answer: b
Explanation: The word ‘pat’ is pushed on to the stack. When the characters of the
stack are popped one by one, the word ‘tap’ is obtained.

8. What is wrong with below code for inorder traversal of inorder threaded binary
tree:

a) inordersuccessor instead of inorderpredecessor must be done


b) code is correct
c) it is code for post order
d) it is code for pre order

Answer: a
Explanation: Property of inorder threaded binary tree is left node with inorder
predecessor and right node with inorder successor information are stored.

9. What does the following function do for a given Linked List with first node as
head?
a) Prints all nodes of linked lists
b) Prints all nodes of linked list in reverse order
c) Prints alternate nodes of Linked List
d) Prints alternate nodes in reverse order

Answer: b
Explanation: fun1() prints the given Linked List in reverse manner.
For Linked List 1->2->3->4->5, fun1() prints 5->4->3->2->1.

Java
10. What will be the output of the following Java program?

a) 1
b) 2
c) 3
d) 4

Answer: b
Explanation: trimTosize() is used to reduce the size of the array that
underlines an ArrayList object.
Output:

You might also like