TCS NQT - cap ability

Test Number 9/11

Q: Which of the following is NOT a type of linked list?
A. Double ended linked list
B.  Double linked list
C.  Simple linked list
D. Circular linked list
Solution: We just have 3 types of linked list among the given options b, c, and d. A double-ended linked list does not exist.
We just have 3 types of linked list among the given options b, c, and d. A double-ended linked list does not exist.
 
Q: Each node of the graph is represented as a _______?
A. Vertex
B. Root
C. Path
D.  Edge
Solution: Every node cannot be a root node and path, the edge is related to the directions of the graph.
Q: Recursion uses more memory space than iteration. Which of the following is/are the valid reason for the same?

A.   It uses the stack instead of a queue

B.   Every recursion call has to be stored

Choose the correct answer from the options given below.
A. Only A
B. Both A and B
C.  Neither A nor B
D.  Only B
Solution: Recursive functions use the stack as the memory space technique. And also as rightly pointed out the call has to be present to store the returned values.
Q: To which of the following domain problem does the knapsack problem belong?
A.  NP-complete
B.  Sorting
C. Optimisation
D.  Linear Solution
Solution: knapsack algorithm is used to find the maximum profit out of the least weight combination possible, therefore it definitely belongs to an optimization domain.
Q: Which of the following is not a valid declaration in C?

1.short int x;

2.signed short x;

3.short x;

4.unsigned short x;
A. 3 and 4
B. 1
C. 2
D. All are valid
Solution: All are valid. First 3 mean the same thing. 4th means unsigned.

 

Expression Evaluation is the favorite question to test your knowledge about combinations of different mathematical operators.
Q: What will be the output of the following code snippet?

#include 
int foo(int* a, int* b)
{
    int sum = *a + *b;
    *b = *a;
    return *a = sum - *b;
}
int main()
{
    int i = 0, j = 1, k = 2, l;
    l = i++ || foo(&j, &k);
    printf("%d %d %d %d", i, j, k, l);
    return 0;
}
 
A. 1 2 1 1
B. 1 1 2 1
C. 1 2 2 1
D. 1 2 2 2
Solution: The control in the logical OR goes to the second expression only if the first expression results in FALSE. The function foo() is called because i++ returns 0(post-increment) after incrementing the value of i to 1. The foo() function actually swaps the values of two variables and returns the value of the second parameter. So, values of variables j and k get exchanged and OR expression evaluates to be TRUE.1 2 1 1
Q: What is correct about the below program?
#include 
int i;
int main()
{
    if (i);
    else
        printf("Ëlse");
    return 0;
}
A. if block is executed.
B. else block is executed
C. It is unpredictable as i is not initialized.
D. Error: misplaced else
Solution: Since i is defined globally, it is initialized with default value 0. The else block is executed as the expression within if evaluates to FALSE. An empty block is equivalent to a semi-colon(;). So the statements if (i);andif (i) {} are equivalent.

We can divide a large program into the basic building blocks known as a function. The function contains the set of programming statements enclosed by {}. A function can be called multiple times to provide reusability and modularity to a program. In other words, we can say that the collection of functions creates a program.
You can be given a function and ask you the functionality of the function
Q: Consider the following C function

1
2
3
4
5
6
7
void swap ( int x, int y )
{
     int tmp;
     tmp = x;
     x = y;
     y = tmp;
}
 In order to exchange the values of two variables a and b:
A. Call swap (a, b)
B. Call swap (&a, &b)
C. swap(a, b) cannot be used as it does not return any value
D. swap(a, b) cannot be used as the parameters passed by value
Solution: The code will not work because the parameters are passed by value. In order to swap the values of x and y the parameters should be passed with reference. The correct code is:
Q: 
A. 
B. 
C. 
D. 
Solution: 

You Have Score    /9