TCS NQT C-MCQ Set - 4

TCS NQT Programming MCQ 

TCS NQT Programming MCQ - SimpleWay2Code


Ques 1. What will be the output of the below program if the below code is run with three command line parameters mentioned below:

Paper Ink Pen

#include
int main(int argc, char ** argv){
char **items;
int j = 3, i;
items = argv;
for(i = 1; (i%4); i++){
int **p = &items[j];
printf("%c", **p);
j--;
}
return 0;
}


a) PIP ✔️
b) Pen
c) Pap
d) Ink

Ques 2.  What is the data type that occupies the least storage in “C” language?
Please give the answer in the blank line: __________

Answer: char


Ques 3. Which of the following is true?

a) Array is a dynamic data structure whose size can be changed while stacks are static data structures whose sizes are fixed.
b) Array elements can be accessed and modified(elements can be added or removed) only at the ends of the array while any elements of the stack can be accessed or modified randomly through their indices.
c) An array can have elements of different data types.
d) Elements of a linked-list can be accessed only sequentially.  ✔️


Ques 4. Improper formation of which of the following data-structures can cause un-intentional looping of a program that uses it.

a) Linked list ✔️
b) Array
c) Queue
d) Stack

Ques 5.  Which of the following statements is FALSE?

a) The time complexity of binary search is O(log n).
b) A linear search requires a sorted list.  ✔️
c) A binary search can operate only on a sorted list.
d) The time complexity of linear search is O(n).

Ques 6. Eesha wrote a function fact( ) in “C” language to calculate factorial of a given number and saved the file as fact.c. She forgot to code the main function to call this fact function. Will she be able to compile this fact.c without the main() function?

a) Yes, she can compile provided the compiler option -no strict-checking is enabled.
b) No, she can not compile as the main function is required to compile any C program file.   ✔️
c) Yes, she can compile as main( ) is not required at compile time.
d) Yes, she can compile and run as the system will supply default values to fact function.

Ques 7. The difference between variable declaration and variable definition is:

a) Declaration and definition are the same. There is no difference.
b) A declaration is used for variables and definitions is used for functions.
c) Declaration associates type to the variable whereas definition associates scope to the variable.
d) Declaration associates type to the variable whereas definition gives the value to the variable.   ✔️


Ques 8. The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively. The post-order traversal of the binary tree is:

a) d e b f g c a   ✔️
b) d e f g b c a
c) e d b f g c a
d) e d b g f c a 

Ques 9. How many times the below loop will be executed?

#include<stdio.h>
int main()
{
int x, y;
for(x=5;x>=1;x--)
{
for(y=1;y<=x;y++)
printf("%d\n",y);
}
}

A. 15  ✔️
B. 11
C. 10
D. 13

Ques 10. The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to a set of sequences (often just two sequences). A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. One form of implementation of LCS function is given below. The function takes as input sequences X[1…m] and Y[1…n], computes the length of the Longest common subsequence between X[1..i] and Y[1..j] for all 1<i < m and 1< j < n, and stores it in C[i,j]. C[m,n] will contain the length of the LCS of X and Y.


function LCSLength(X[1..m], Y[1..n])
C = array(0..m, 0..n)
for i:= 0..m
C[i,0] =0
for j := 0..n
C[0,j] = 0d
for i := 1..m
for j := 1..n
if X[i]  =  Y[j]
C[i,j] := C[i-1, j-1] + 1
else
C[i,j] := max(C[i, j-1], C[i-1, j])
return C[m, n]

Eesha used the above algorithm to calculate the LCS length between “kitten” and “string”. What was the result she got? Please give the answer in the blank line. ___________

 Answer: 2





This Blog is Hard work !

Can you give me a treat 😌

Post a Comment

0 Comments