Tcs Questions
Tcs Questions
time cutoff
Data Types
Functions
Scope
Arrays
Command Line
Linked Lists
OOPs
Neelam wants to share her code with a colleague, who may modify it. Thus she wants to
include the date of the program creation, the author and other she wants to include the date
of the program creation, the author and other information with the program. What
component should she use?
A
header files
B
Iteration
C
Comments
D
pre processor
SkipHide
What is the output of the following code statements? The compiler saves the first integer at
the memory location 4165 and the rest at consecutive memory spaces in order of
declaration. Integer is one byte long.
integer a
pointer c, d
a = 30c = &a
c = &a
d = c
a = a + 10
print *c
A
40
B
30
C
4165
D
4166
SkipHide
A data type is stored as a 6 bit signed integer. Which of the following cannot be represented
by this data type?
A
-12
B
6
C
18
D
32
SkipHide
A language has 28 different letters in total. Each word in the language iscomposed of
maximum 7 letters. You want to create a data-type to store a word ofthis language. You
decide to store the word as an array of letters. How many bits will you assign to the data-
type to be able to store all kinds of words of the language.
A
35
B
7
C
28
D
196
SkipHide
A
0 to 1000
B
0 to 1024
C
0 to 1023
D
0 to 1025
Parul takes as input two numbers: a and b. a and b can take integer valuesbetween 0 and
255. She stores a, b and c as 1-byte data type. She writes the following code statement to
process a and b and put the result in c.
c = a + 2*b
To her surprise her program gives the right output with some input values of a and b, while
gives an erroneous answer for others. For which of the following inputs will it give a wrong
answer?
A
a = 200 b = 10
B
a = 10 b = 200
C
a = 50 b = 100
D
a = 100 b = 50
SkipHide
A
Linker
B
Loader
C
Executer
D
Compiler
SkipHide
Tricha wants to store a list of binary data.Which of following data types should she use?
A
Boolean
B
Integer
C
Character
D
Boolean
SkipHide
Which of the following options is an exception to being a part of composite data types?
A
Union
B
Structure
C
Arrays
D
Stacks
SkipHide
A
int __v1;
B
int __1v;
C
int __V1;
D
None
A
It is not standard form
B
To avoid conflicts since assemblers and loaders use such names
C
To avoid conflicts since library routines use such names
D
To avoid conflicts with environment variables of an operating system
A
int number;
B
float rate;
C
int variable_count;
D
int $main;
A
They can contain alphanumeric characters as well as special characters
B
It is not an error to declare a variable to be one of the keywords(like goto, static)
C
Variable names can’t start with a digit
D
Variable can be of any length
What will be the output? #include <stdio.h> int main() { int main = 5; printf(“%d”, main);
return 0; }
A
compile-time error
B
run-time error
C
run without any error and prints 5
D
experience infinite looping
A
friend
B
true
C
volatile
D
export
The format identifier ‘%i’ is also used for _____ data type?
A
char
B
double
C
float
D
int
A
struct {char name[10], int age};
B
typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
C
typedef int Boolean;
D
all of the mentioned
A
Basic datatype of C
B
Qualifier
C
short is the qualifier and int is the basic datatype
D
All of the mentioned
What is the output of this C code? #include <stdio.h> int main() { signed char chr; chr =
128; printf(“%d\n”, chr); return 0; }
A
128
B
-128
C
Depends on the compiler
D
None of the mentioned
A
4 Bytes
B
8 Bytes
C
Depends on the system/compiler
D
Cannot be determined
A
int
B
struct
C
float
D
double
#include <stdio.h>
int main()
float x = ‘a’;
printf(“%f”, x);
return 0;
A
97.000000
B
run time error
C
a.0000000
D
a
SkipHide
A
char > int > float
B
int > char > float
C
char < int < double
D
double > char > int
A
4 Bytes
B
8 Bytes
C
Depends on the system/compiler
D
Cannot be determined
SkipHide
A
int
B
struct
C
float
D
double
SkipHide
What is the output of this C code?
#include <stdio.h>
int main()
float x = ‘a’;
printf(“%f”, x);
return 0;
}
A
97.000000
B
run time error
C
a.0000000
D
a
SkipHide
A
Compiler and linker implementations
B
Assemblers and loaders implementations
C
C language
D
None
SkipHide
Consider on following declaration:
(i) short i=10;
(ii) static i=10;
(iii) unsigned i=10;
(iv) const i=10;
A
Only (iv) is incorrect
B
Only (ii) and (iv) are incorrect
C
Only (ii),(iii) and (iv) are correct
D
All are correct declaration
SkipHide
A
float PI = 3.14;
B
#define PI 3.14;
C
double PI = 3.14;
D
int PI = 3.14;
The format identifier ‘%i’ is also used for _____ data type?
A
char
B
double
C
int
D
float
Literal means ?
A
a string.
B
a string constant.
C
a character.
D
an alphabet.
SkipHide
#include <stdio.h>
int main() {
int main = 3;
printf(“%d”, main);
return 0;
}
A
It will cause a compile-time error
B
It will cause a run-time error
C
It will run without any error and prints 3
D
It will experience infinite looping
SkipHide
Functions
What is the difference between a function and a method?
A
Function is a named code unlike method which is a part of an object
B
Function contained in an object is called a method
C
Function cannot change variables outside its scope unlike method
D
There is no difference between the two
SkipHide
function modify(a,b)
Integer c,d=2
c= a*d+ b
return c
}
function calculate()
integer a = 5, b = 20, c
integer d= 10
c = modify(a, b);
c = c+ d
print c
A
80
B
40
C
32
D
72
What is the term given to the variable whose scope is beyond all the scopes i.e., it can be
accessed by all the scopes?
A
Universal Variable
B
Global Variable
C
External Variable
D
Auto Variable
Anu wants to make a function that is not bound to any identifier. Which of the following
functions should she incorporate in her program?
A
Only Private
B
Protected and Private
C
Public and No Modifier
D
Only No Modifier
Which of the following accessibility modes can be the specifier of a top level class’?Top-
level classes can only have public, abstract, and final modifiers, and it is also possible to not
define any class modifiers at all. This is called default/package accessibility. Besides that,
private, protected, and static modifiers cannot be used when declaring top-level classes.
Private, Protected, Public, No Modifier
A
Only Private
B
Protected and Private
C
Public and No Modifier
D
Only No Modifier
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory An accessible member function or data member for an object are accessed by
the statement objectname.functionname or objectname. data member name respectively.
class brush
{
Private:
integer size, colorcode
function getdata( ) {--}//Statement 1
public:
integer name // Statement 2
function putdata(){...}
}
function main
{
brush b1, b2
print bl.name //Statement 3
b2.getdata() //Statement 4
}
A
Statement 1
B
Statement 2
C
Statement 3
D
Statement 4
A
Statement 1
B
Statement 2
C
Statement 3
D
Statement 4
SkipHide
Function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
A
Anonymous Function
B
Friend Function
C
Null Function
D
Global Function
function factorial(n)
{
if(n equals 1)
return 1
else
— MISSING STATEMENT —
end
}
A
return factorial(n-1)
B
return n*factorial(n)
C
return n*(n-1)
D
return n*factorial(n-1)
#include <stdio.h>
int main() {
int y = 10000;
int y = 34;
printf(“Hello World! %d\n”,y);
return 0;
}
A
Compile time error
B
Hello World! 34
C
Hello World! 1000
D
Hello World! followed by a junk value
SkipHide
Choose the correct answer
Afzal writes a piece of code, where a set of three lines occur around 10 times in different
parts of the program. What
B
Null pointer
C
Wild pointer
D
Heterogeneous list follows the same procedure as the homogeneous list. Hence no different
pointer is required.
Talika wants to implement heterogeneous linked list for her project. Which of the following
will help her do the same.
A
This is bad programming practice and should not be done.
B
void pointer
C
Decision Making
D
Overloading
Choose the correct answer
Saumya writes a code which has a function which calls itself. Which programming concept
is Saumya using?
A
Recursion
B
Overloading
C
Decision Making
D
This is Bad programming And should not be done O.OO %
function calculate( n )
{
if(n equals 5)
return 5
else
return (n + calculate(n-5))
end
}
Shishir calls the function by the statement, calculate(20). What value will the function
return?
A
20
B
30
C
40
D
50
A
Always -1
B
0 if a equals b, -1 otherwise
C
1 if a > b, -1 if a < b, 0 otherwise
D
-1 if a > b, 1 if a < b, 0 otherwise
A
Value of elements in array
B
First element of the array
C
Base address of the array
D
Address of the last element of array
int (*ptr)[10];
A
ptr is array of pointers to 10 integers
B
ptr is a pointer to an array of 10 integers
C
ptr is an array of 10 integers
D
ptr is an pointer to array
What will happen if in a C program you assign a value to an array element whose subscript
exceeds the size of array?
A
The element will be set to 0.
B
The compiler would report an error.
C
The program may crash if some important data gets overwritten.
D
The array size would appropriately grow
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.
SkipHide
#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
SkipHide
What is the output of this C code? #include <stdio.h> void main() { m(); void m()
{ printf(“SimpleWay2Code”); } }
A
SimpleWay2Code
B
Compile time error
C
Nothing
D
Varies
SkipHide
What is the output of this C code? #include <stdio.h> void main() { static int x = 3; x++; if
(x <= 5) { printf(“hello”); main(); } }
A
Run time error
B
hello
C
Infinite hello
D
hello hello
The value obtained in the function is given back to main by using ________ keyword?
A
return
B
static
C
new
D
volatile
What is the problem in the following declarations? int func(int); double func(int); int
func(float);
A
A function with same name cannot have different signatures
B
A function with same name cannot have different return types
C
A function with same name cannot have different number of parameters
D
All of the mentioned
A
int
B
float
C
double
D
depends on the data type of the parameter
What is the output of this code having void return-type function? #include <stdio.h>
void foo() { return 1; } void main() { int x = 0; x = foo(); printf(“%d”, x); }
A
1
B
Runtime error
C
Compile time error
The output of the code below is #include <stdio.h> void main() { int k = m(); printf(“%d”,
k); } void m() { printf(“hello”); }
A
hello 5
B
Error
C
Nothing
D
Garbage value
The output of the code below is #include <stdio.h> int *m() { int *p = 5; return p; } void
main() { int *k = m(); printf(“%d”, k); }
A
5
B
Junk value
C
Error
SkipHide
What will be the output of the program? #include<stdio.h> int main() { int i=1; if(!i)
printf(“SimpleWay2Code,”); else { i=0; printf(“C-Program”); main(); } return 0; }
A
prints “SimpleWay2Code, C-Program” infinitely
B
prints “C-Program” infinetly
C
prints “C-Program, SimpleWay2Code” infinitely
D
Error: main() should not inside else statement
SkipHide
How many times the program will print “SimpleWay2Code” ? #include<stdio.h> int
main() { printf(“SimpleWay2Code”); main(); return 0; }
A
Infinite times
B
32767 times
C
65535 times
D
Till stack overflows
a = a + rand();
b = b + rand();
A
O(N * M) time, O(1) space
B
O(N + M) time, O(N + M) space
C
O(N + M) time, O(1) space
D
O(N * M) time, O(N + M) space
int a = 0, i = N;
while (i > 0) {
a += i;
i /= 2;
A
O(N)
B
O(Sqrt(N))
C
O(N / 2)
D
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
A
X will always be a better choice for small inputs
B
X will always be a better choice for large inputs
C
Y will always be a better choice for small inputs
D
X will always be a better choice for all inputs
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
A
O(n)
B
O(nLogn)
C
O(n^2)
D
O(n^2Logn)
a = a + i + j;
}
A
O(N)
B
O(N*log(N))
C
O(N*log(N))
D
O(N*N)
A
Best case
B
Worst case
C
Average case
D
Null case
A
Pivot is the median of the array
B
Pivot is the smallest element
C
Pivot is the middle element
D
None of the mentioned
A
O(n)
B
O(log n)
C
O(n2)
D
O(n log n)
A
O(n)
B
O(log n)
C
O(n2)
D
O(n log n)
A
O(n)
B
O(log n)
C
O(n2)
D
O(n log n)
SkipHide