TCS NQT 2021 Programming Logic

TCS NQT 2021
Programming Logic 


Question 1- What will be the output


public class Main {


public static void main(String[] args)

{

           int $ = 5;

}

}


1.Nothing will print

2.Symbol not found Error.

3.Runtime Error

4.Compile time error


Answer- 1.Nothing will print


Question 2-


class Main

{  

      public static void main(String args[])

      {

          int i,j,x=0;

          for(i=0;i<5;i++)

                for (j=0;j<5;j++){

                        x=(i+j-1);

                         System.out.print(x);

                          break;

                        }

             System.out.print(x);

        }

  }


What will be printed when the above sample code is executed.


Enter your answer ONLY as a NUMERAL, in the box.


Answer-   -101233


Question 3- Which of the following options best suits for ‘Memory Leak Occurred’


1.Resource allocation pending while debugging the code

2.Program releases resources allocated in the memory

3.Program does not free the memory which is allocated dynamically

4.Occurs due to address assignment failure.


Answer- Program does not free the memory which is allocated dynamically.


Question 4- What among the following is a server based paradigm


1.Request for Information(RFI)

2.Data Validation Routine

3.Cloud computing

4.Total cost of Ownership.


Answer- Request for information


Question 5- When we declare constant pointer to integer, we CANNOT change:


1.Value pointed by pointer

2.Either addressing pointer variable or value at that address

3.Changes are not permitted

4.Address in pointer variable.


Answer- Address in the pointer variable.


Question 6- Given here is a scenario. Consider the graph algorithm and answer the given question.


John wants to go to different locations of the city in which he is. He has listed all of them down. However he wants to visit one location before visiting some other location. What application of graphs can he use to determine that location?


1.DFS

2.Dijsktra’s

3.BFS

4.Topological Sorting


Answer- Dijkstra’s


Question 7 - Find Prefix and Postfix for the below Infix problem statement:


Prefix Expression: 11 20 5 20 15 - 6 5  ^^ * / +

Postfix Expression: + 11 / 20 * 5 ^^ - 20 15 6 5


Prefix Expression: + 11 / 20 * 5 ^^ - 20 15 6 5

Postfix Expression: 11 20 5 20 15 - 6 5 ^^ * / +


Prefix Expression: 11 20 15 20 5 - ^^ * 6 5 / +

Postfix Expression: + 20 / 11 * 5 - 20 ^^ 15 6 5


Prefix Expression: 11 20 5 20 15 - ^^ * / + 6 5

Postfix Expression: + 11 / ^^ - 20 * 5 20 15 6 5


Question 8 - There are two integer numbers X and Y, and the value of X and Y is in between 0 to 25. User stores the value under 5 bit number. How many minimum bit is required to store the result of the below expression?


Res = 3*(X-Y)


7

5

8

6


Answer-


Question 9- Write the name of library of functions which is used to perform arithmetic operations on BigInteger and BigDecimal


Answer- MathContext


This question in TCS NQT was wrong. Incorrect options were given ….

Question 10 -  Consider the following tree what will be the preorder traversal.


1. A B C D E F G H I

2. D H E B I F G C A

3. H I D E F G B C A

4 .D H E B A F I G C


Answer- ABDEHCFIG

Comments

Post a Comment