Tcs Programming Mcquestions
Tcs Programming Mcquestions
Tcs Programming Mcquestions
Programming Concepts:
Iteration, recursion, procedural vs OOP.
C Language: call by value/reference, basic and derived data types,
storage class, scope and visibility, basics of pointers, basic header files,
library functions, branching and looping, command line arguments,
user-defined functions.
Algorithms:
Basic search algorithms, basic sort algorithms (tree traversal, dynamic
programming, etc)
Data Structures:
Array, Stack, Queue, List (tree, hash table, etc)
Value 12 10 8 11 14 5 5
Weight 4 6 5 7 3 10 12
She wanted to bring back the maximum value of items but she was not
able to carry more than 10 kgs. Using dynamic programming, what is
the maximum value of the items that she could carry back with her.
Answer: 26
2) In C language, if a function return type is not explicitly defined then
it defaults to what data type?
Answer: Int
a) Push, pop
b) Push, pop, remove
c) Push, pop, add, remove
d) Push,pop,add,remove,substitute
a) Get back the memory that was released earlier using dree() function
b) Reallocate a file pointer when switching between files
c) Change the size of an array
d) Change the size of the dynamically allocated memory
a) Tree
b) Queue
c) Linked list
d) Stack
8) The pseudo code below sorts an array using bubble sort. Here A is
the array and the” n” is the number of elements in it. Function swap
exchanges the value of 2 given value.
This function is called with A and 7 as parameter where the array a
initially contains the element 64, 34, 25,12, 22, 11, 9
a) 34 25 12 22 11 9 64
b) 25 12 22 11 9 34 64
c) 11 9 12 22 25 34 64
d) 12 11 9 22 25 34 64
Answer: 25 12 22 11 9 34 64
9) #define is used to
a) Define a variable
b) Define a macro
c) Define a function
d) Define a constant
a) Extern
b) Dynamic
c) Register
d) Auto
Answer: Dynamic
a) Stack
b) Queue
c) Linked list
d) Array
Answer: Stack
13) #include
Main(int argc,char**argv)
{
printf(“%s\n”,argv[–argc]);
Return 1;
}
The above program was run with the following command line
parameters
Asha usha nisha easha
What was the output?
a) Nisha
b) Unable to run due to compilation error
c) No output,run time error
d) easha
Answer: easha
TCS Ninja Programming MCQs (Standard section)
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
————————————————
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
————————————————
Answer: d
————————————————
————————————————
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
————————————————
Answer: d
TCS Ninja Programming Concepts (Advanced Section)
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?
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
A. 15
B. 11
C. 10
D. 13
Solution: Option A
————————————————
A. Disk
B. Stack
C. Heap
D. Code
Solution: Option B
————————————————
A. double
B. float
C. int
D. long int
————————————————
int main
{
float f = 0.1;
if (f = 0.1)
printf (“yes”);
else print (“no”);
}
————————————————
Solution: Option C
Explanation: If the index of the array size is exceeded, the program will
crash. Hence “option c” is the correct answer. But the modern
compilers will take care of this kind of errors.
————————————————
Solution: Option B
————————————————
Solution: Option C
Explanation: The statement ‘C’ is correct. When we pass an array as a
function argument, the base address of the array will be passed.
————————————————
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
Solution: Option C
Explanation:
Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an
integer array with a size of 5 and it is initiapzed to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is
incremented by 1(i++ means 2++ so i=3)
Step 6: printf(“%d, %d, %d”, i, j, m); It prints the value of the variables i, j,
m
Hence the output of the program is 3, 2, 15
————————————————
A. Yes
B. No
Solution: Option B
Explanation: No, both the statements are the same. It is the prototype
for the function fun() that accepts one integer array as a parameter and
returns an integer value.
————————————————
10) Are the expressions arr and &arr same for an array of 10 integers?
A.Yes
B.No
Solution: Option B
Explanation: Both mean two different things. arr gives the address of
the first int, whereas the &arr gives the address of array of ints.
————————————————
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?
Solution: Option B
————————————————
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.
————————————————
2: int fun();
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.