TCS Ninja Programming MCQ's Syllabus
TCS Ninja Programming MCQ's Syllabus
TCS Ninja Programming MCQ's Syllabus
1)
#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;
}
The above code is run with three command line parameters mentioned here: Paper Ink Pen
What will be the output of the above program?
a) PIP
b) Pen
c) Pap
d) Ink
Answer: a
————————————————
2) 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
Answer: a
————————————————
3) What is the data type that occupies the least storage in “C” language? Please give the answer in the
blank line: __________
Answer: char
————————————————
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.
Answer: d
————————————————
Answer: b
————————————————
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.
Answer: b
————————————————
1) 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
Answer: a
————————————————
2) Eesha wrote a recursive function that takes the first node in a linked list as an argument, reverses the
list, returning the first Node in the result. The pseudo code for this function is given below. However,
she did not get the correct result. In which line number did she make a mistake?
first.next = null;
return rest.next;
————————————————
3) 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.
C = array(0..m, 0..n)
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]
else
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
————————————————
11) Which of the fplowing statements should be used to obtain a remainder after dividing 3.14 by 2.1?
A. rem = 3.14 % 2.1;
B. rem = modf(3.14, 2.1);
C. rem = fmod(3.14, 2.1);
D. Remainder cannot be obtain in floating point division.
Solution: Option C
Explanation:
fmod(x,y) – Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.
————————————————
12) What are the types of pnkages?
A. Internal and External
B. External, Internal and None
C. External and None
D. Internal
Solution: Option B
————————————————
13) Which of the following special symbols are allowed in a variable name?
A. * (asterisk)
B. | (pipepne)
C. -(hyphen)
D. _(underscore)
Solution: Option D
Explanation: Variable names in C are made up of letters (upper and lower case) and digits. The underscore
character (“_”) is also permitted. Names must not begin with a digit.
————————————————
14) Is there any difference between following declarations?
1 : extern int fun();
2 : int fun();
A. Both are identical
B. No difference, except extern int fun(); is probably in another file
C. int fun(); is overrided with extern int fun();
D. None of these
Answer: Option B
Explanation: extern int fun(); declaration in C is to indicate the existence of a global function and it is defined
externally to the current module or in another file.
int fun(); declaration in C is to indicate the existence of a function inside the current module or in the same
file.