Welcome Guest

Technical Questions for SAPIENT

Q. No. :1
Question : How will you free the memory allocated by the following program?
 
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}

A :
memfree(int p);
B :
dealloc(p);
C :
malloc(p, 0);
D :
free(p);
Answer: D
Q. No. :2
Question :
 int z, x=5, y=-10, a=4,b=2;
z = x++ - - -y * b / a
What number will z in the sample code above contain?
A :
9
B :
10
C :
11
D :
12
Answer: B
Q. No. :3
Question : What will be the output of the program ?
 
#include<stdio.h>

struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"} };

printf("%d", c[1].courseno);
printf("%s\n", (*(c+2)).coursename);
return 0;
}

A :
103 Dotnet
B :
102 Java
C :
103 PHP
D :
104 DotNet
Answer: A
Q. No. :4
Question :On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?
 
#include<stdio.h>

int main()
{
int i, fss;
char ch, source[20] = "source.txt", target[20]="target.txt", t;
FILE *fs, *ft;
fs = fopen(source, "r");
ft = fopen(target, "w");
while(1)
{
ch=getc(fs);
if(ch==EOF)
break;
else
{
fseek(fs, 4L, SEEK_CUR);
fputc(ch, ft);
}
}
return 0;
}

A :
r n
B :
Trh
C :
err
D :
None of above
Answer: B
Solution
Q. No. :5
Question : What will be output of the following program?
  #include<stdio.h>
 int main()
{    
int a=2,b=7,c=10;    
c=a==b;    
printf("%d",c);    
return 0;
}

A :
2
B :
10
C :
7
D :
0
Answer: D
Solution
Q. No. :6
Question : What will be the output of the program ?
#include<stdio.h>

int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT);
return 0;
}

A :
-1, 0, 1, 2, 3, 4
B :
Error
C :
0, 1, 6, 3, 4, 5
D :
0, 0, 6, 7, 8, 9
Answer: B
Q. No. :7
Question :What will be output when you will execute following c code?
 #include<stdio.h>
void main()
{    
char arr[7]="Network";    
printf("%s",arr);
}

A :
Network
B :
N
C :
Garbage Value
D :
Compilation error
Answer: C
Solution
Q. No. :8
Question :int var1;
If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?
A :
Yes; it can be referenced through the register specifier
B :
No; it would have to have been initially declared as a static variable
C :
No; it would need to have been initially declared using the global keyword.
D :
Yes; it can be referenced through the publish specifier
Answer: C
Q. No. :9
Question :

What will be the output of the program?

 
#include<stdio.h>

int main()
{
    int fun(int);
    int i=3;
    fun(i=fun(fun(i)));
    printf("%d\n", i);
    return 0;
}
fun(int i)
{
    i++;
    return i;
}

A :
5
B :
4
C :
Error
D :
Garbage value
Answer: A
Solution
Q. No. :10
Question : What will the function rewind() do?
A :
Reposition the file pointer to a character reverse.
B :
Reposition the file pointer stream to end of file.
C :
Reposition the file pointer to begining of that line.
D :
Reposition the file pointer to begining of file.
Answer: D
Solution
Q. No. :11
Question :
 char *buffer = "0123456789";
char *ptr = buffer;
ptr += 5;
printf( "%s\n", ptr );
printf( "%s\n", buffer );
What will be printed when the sample code above is executed?
A :
56789
0123456789
B :
0123456789
0123456789
C :
5123456789
5123456789
D :
0123456789
56789
Answer: A
Q. No. :12
Question :Consider the following program and what will be content of t?
 
#include<stdio.h>

int main()
{
FILE *fp;
int t;
fp = fopen("DUMMY.C", "w");
t = fileno(fp);
printf("%d\n", t);
return 0;
}

A :
size of "DUMMY.C" file
B :
The handle associated with "DUMMY.C" file
C :
Garbage value
D :
Error in fileno()
Answer: B
Solution
Q. No. :13
Question : What will be the output
 #include
void main()
{    
 int check=2;     
switch(check)
{        
case 1: printf("D.W.Steyn");        
case 2: printf(" M.G.Johnson");        
case 3: printf(" Mohammad Asif");        
default: printf(" M.Muralidaran");     
}

A :
M.G.Johnson
B :
M.Muralidaran
C :
M.G.Johnson Mohammad Asif M.Muralidaran
D :
Compilation error
Answer: C
Solution
Q. No. :14
Question : What will be the output of the program?
 
#include<stdio.h>

typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e;
e.err=1;
printf("%d\n", e.err);
return 0;
}

A :
0
B :
1
C :
2
D :
error
Answer: B
Q. No. :15
Question :What number is equivalent to -4e3?
A :
-4000
B :
-400
C :
-40
D :
0.004
Answer: A
Q. No. :16
Question : What will be output of the following program?
  #include<stdio.h>
 int main(){   
 int i=5,j;   
 j=++i+++i+++i;  
  printf("%d %d",i,j);  
  return 0;
}

A :
8 24
B :
8 21
C :
5 24
D :
8 23
Answer: A
Solution
Q. No. :17
Question : What will be the output of the program?
 
#include<stdio.h>
#include<stdarg.h>
void fun1(char, int, int *, float *, char *);
void fun2(char ch, ...);
void (*p1)(char, int, int *, float *, char *);
void (*p2)(char ch, ...);

int main()
{
char ch='A'; int i=10;
float f=3.14; char *p="Hello";
p1=fun1;
p2=fun2;
(*p1)(ch, i, &i, &f, p);
(*p2)(ch, i, &i, &f, p);
return 0;
}
void fun1(char ch, int i, int *pi, float *pf, char *p)
{
printf("%c %d %d %f %s \n", ch, i, *pi, *pf, p);
}
void fun2(char ch, ...)
{
int i, *pi; float *pf; char *p;
va_list list;
printf("%c ", ch);
va_start(list, ch);
i = va_arg(list, int);
printf("%d ", i);

pi = va_arg(list, int*);
printf("%d ", *pi);
pf = va_arg(list, float*);
printf("%f ", *pf);
p = va_arg(list, char *);
printf("%s", p);
}

A :
A 10 3.14
A 10 3.14
B :
A 10 10 3.140000 Hello
A 10 10 3.140000 Hello
C :
A 10 Hello
A 10 Hello
D :
Error
Answer: B
Q. No. :18
Question :Which of the following statements are correct about the program?
 
#include<stdio.h>

long fun(int num)
{
int i;
long f=1;
for(i=1; i<=num; i++)
f = f * i;
return f;
}

A :
The function calculates the value of 1 raised to power num.
B :
The function calculates the square root of an integer
C :
The function calculates the factorial value of an integer
D :
None of above
Answer: C
Q. No. :19
Question :

What will be the output of the program?

#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
    int i=10, j=5, k=0;
    k = MAN(++i, j++);
    printf("%d, %d, %d\n", i, j, k);
    return 0;
}
A :
12, 6, 12
B :
11, 5, 11
C :
11, 5, Garbage
D :
12, 6, Garbage
Answer: A
Solution
Q. No. :20
Question :What will be the output of the program?
 
#include<stdio.h>

int main()
{
typedef int arr[5];
arr iarr = {1, 2, 3, 4, 5};
int i;
for(i=0; i<4; i++)
printf("%d,", iarr[i]);
return 0;
}

A :
1,2,3,4
B :
1,2,3,4,5
C :
No output
D :
Error: Cannot use typedef with an array
Answer: A
Q. No. :21
Question : What will be output of the following program?
 #include<stdio.h>
int main()
{    
printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L));   
return 0;
}

A :
8 4 10
B :
8 8 8
C :
8 4 8
D :
4 4 8
Answer: A
Solution
Q. No. :22
Question :If the two strings are identical, then strcmp() function returns
A :
-1
B :
1
C :
0
D :
Yes
Answer: C
Solution
Q. No. :23
Question :Which of the following errors would be reported by the compiler on compiling the program given below?
 
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");

case 2:
printf("Second");

case 3 + 2:
printf("Third");

case 5:
printf("Final");
break;

}
return 0;
}

A :
There is no break statement in each case.
B :
Expression as in case 3 + 2 is not allowed.
C :
Duplicate case case 5:
D :
No error will be reported.
Answer: C
Solution
Q. No. :24
Question :
 
char* myFunc (char *ptr)
{
 ptr += 3;
 return (ptr);
}
int main()
{
 char *x, *y;
 x = "HELLO";
 y = myFunc (x);
 printf ("y = %s \n", y);
 return 0;
}
What will print when the sample code above is executed?
A :
HELLO
B :
ELLO
C :
LLO
D :
LO
Answer: D
Q. No. :25
Question :What is the notation for following functions?
 
1.  int f(int a, float b)
{
/* Some code */
}

2. int f(a, b)
int a; float b;
{
/* Some code */
}

A :
1. KR Notation
2. ANSI Notation
B :
1. Pre ANSI C Notation
2. KR Notation
C :
1. ANSI Notation
2. KR Notation
D :
1. ANSI Notation
2. Pre ANSI Notation
Answer: C
Q. No. :26
Question :What will be output?
  void main()
{
int a=5;
 float b;
printf("%d",sizeof(++a+b));
printf(" %d",a);
}

A :
2 6
B :
4 6
C :
2 5
D :
4 5
Answer: D
Solution
Q. No. :27
Question : What is the purpose of fflush() function.
A :
flushes all streams and specified streams.
B :
flushes only specified stream.
C :
flushes input/output buffer.
D :
flushes file buffer.
Answer: A
Solution
Q. No. :28
Question : Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);

A :
char p = *malloc(100);
B :
char *p = (char) malloc(100);
C :
char *p = (char*)malloc(100);
D :
char *p = (char *)(malloc*)(100);
Answer: C
Q. No. :29
Question :Which of the following statements are correct about 6 used in the program?
int num[6];
num[6]=21;
A :
In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type.
B :
In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.
C :
In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size.
D :
In both the statement 6 specifies array size.
Answer: B
Solution
Q. No. :30
Question :"My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above.
A :
printf("My salary was increased by 15%!\n");
B :
printf("My salary was increased by 15'%'!\n");
C :
printf("\"My salary was increased by 15%%!\"\n");
D :
printf("\"My salary was increased by 15'%'!\"\n");
Answer: C
Q. No. :31
Question :Consider the following two pieces of codes and choose the best answer
Code 1:

switch (x) {

case  1:

cout <<”x is 1”;

break;

case 2:

                cout <<”x is 2”;

                break;

default:

                cout <<”value of x unknown”;

}


CODE 2:-
 

If (x==1){

                Cout <<”x is 1”;

                }

Else if (x==2){

                Cout << “x is 2”;

                }

Else{

                Cout <<”value of x unknown”;

}

A :
Both of the above code fragments have the same behaviour
B :
Both of the above code fragments produce different effects
C :
The first code produces more results than second
D :
The second code produces more results than first.
Answer: A
Q. No. :32
Question :Void pointer is
A :
It is a pointer which cannot be defined
B :
Specific data type and it couldn't hold the access of some other type of variable
C :
A pointer pointing to an array
D :
None
Answer: D
Q. No. :33
Question :Which of the following statement is true regarding cin statement?
A :
cin statement must contain a variable preceded by >> operator
B :
cin does not process the input until user presses RETURN key
C :
you can use more than one datum input from user by using cin
D :
all of above
Answer: D
Q. No. :34
Question :Regarding following statement  which of the statements is true?
const int pathwidth=100;
A :
Declares a variable pathwidth with 100 as its initial value
B :
Declares a construction pathwidth with 100 as its initial value
C :
Declares a constant pathwidth whose value will be 100
D :
Constructs an integer type variable with pathwidth as identifier and 100 as value
Answer: C
Q. No. :35
Question :In an assignment statement
A :
The lvalue must always be a variable
B :
The rvalue might be a constant, a variable, an expression or any combination of these
C :
The assignment always takes place from right to left and never the other way
D :
All of above
Answer: D
Q. No. :36
Question :Dynamic binding is
A :
Resolving the function call at compile time
B :
Defining binding statically
C :
Resolving a function call at runtime
D :
None
Answer: C
Q. No. :37
Question :Multilevel Inheritance means
A :
Procedure of deriving a class from derived class
B :
Deriving a class from a single base class
C :
Single base class deriving two classes
D :
None of the above
Answer: A
Q. No. :38
Question :Regarding the use of  new line character (/n) and endl manipulator with cout statement
A :
Both ways are exactly same
B :
Both are similar but endl additionally performs flushing of buffer
C :
endl can’t be used with cout
D :
\n can’t be used with cout
Answer: B
Q. No. :39
Question :In case of arguments passed by values when calling a function such as z=addidion(x,y),
A :
Any modifications to the variables x & y from inside the function will not have any effect outside the function.
B :
The variables x and y will be updated when any modification is done in the function
C :
The variables x and y are passed to the function addition
D :
None of above are valid.
Answer: A
Q. No. :40
Question :If you use same variable for two getline statements
A :
Both the inputs are stored in that variable
B :
The second input overwrites the first one
C :
The second input attempt fails since the variable already got its value
D :
You can not use same variable for two getline statements
Answer: B
Q. No. :41
Question :Overloaded functions are
A :
Very long functions that can hardly run
B :
One function containing another one or more functions inside it.
C :
Two or more functions with the same name but different number of parameters or type.
D :
None of above
Answer: D
Q. No. :42
Question :Which of the following is not a type of inheritance?
A :
Hierarchical
B :
Derived
C :
Multipath
D :
Multilevel
Answer: B
Q. No. :43
Question :By default C++ classes are
A :
Private
B :
Public
C :
Protected
D :
None
Answer: A
Q. No. :44
Question :Identify the correct statement regarding scope of variables
A :
Global variables are declared in a separate file and accessible from any program.
B :
Local variables are declared inside a function and accessible within the function only.
C :
Global variables are declared inside a function and accessible from anywhere in program.
D :
Local variables are declared in the main body of the program and accessible only from functions.
Answer: B
Q. No. :45
Question :Observe the following block of code and determine what happens when x=2?

switch (x){

case 1:

case 2:

case 3:

                cout<< "x is 3, so jumping to third branch";

                goto thirdBranch;

default:

                cout<<"x is not within the range, so need to say Thank You!";

                }


A :
Program jumps to the end of switch statement since there is nothing to do for x=2
B :
The code inside default will run since there is no task for x=2, so, default task is run
C :
Will display x is 3, so jumping to third branch and jumps to third Branch.
D :
None of above
Answer: C
Q. No. :46
Question :Which data structure is needed to convert infix notation to prefix notation?
A :
Stack
B :
Queue
C :
Tree
D :
Graph
Answer: A
Q. No. :47
Question :For the sequence
8, 2, 4, 6, 9,7, 10, 1, 5, 3
Perform the splitting part of merge sort. The second stage of the merge operation will give which of the following output?
A :
2 8 4 6 9 7 10 1 5 3
B :
2 4 6 9 8 1 3 5 7 10
C :
2 4 8 6 9 1 7 10 3 5
D :
2 8 4 6 9 7 10 1 5 3
Answer: C
Q. No. :48
Question :Space complexity refers to
A :
Memory required by an algorithm needs to run to completion.
B :
Complexities involved in space mission transmission
C :
Complexity of a 3 D graphics creation
D :
None
Answer: C
Q. No. :49
Question :What is time required to insert an element in a stack with linked implementation?
A :
1
B :
Log2n
C :
n
D :
n Log2n
Answer: B
Q. No. :50
Question :5-2-3*5-2 evaluates 18 then
A :
- left associative * has precedence over -
B :
- right associative * has precedence over -
C :
* left associative - has precedence over *
D :
* right associative - has precedence over *
Answer: D
Q. No. :51
Question :which one of the following is the recursive travel technique.
A :
depth first search 
B :
preorder
C :
breadth first search 
D :
None
Answer: A
Q. No. :52
Question :When converting binary tree into extended binary tree, all the original nodes in binary tree are
A :
internal nodes on extended tree
B :
external nodes on extended tree
C :
vanished on extended tree
D :
None of above
Answer: A
Q. No. :53
Question :For the sequence
500, 535, 512, 721, 436, 611, 624, 632, 643
Lexicographic sort gives time complexity of
A :
O(39)
B :
O(29)
C :
O(28)
D :
O(27)
Answer: D
Q. No. :54
Question :How many operations are required in Round Robin algorithm used in minimum spanning tree, if an appropriate implementation of the priority queue is used.
A :
O(e logn)
B :
O(log logn)
C :
O(n log e)
D :
O(e log logn)
Answer: D
Q. No. :55
Question :A list is ordered from smallest to largest when a sort is called. Which sort would take shortest time to sot from maximum to minimum.
A :
Heap Sort
B :
Bubble Sort
C :
Quick sort
D :
Selection sort
Answer: C
Q. No. :56
Question :Which of the following statements are true in case of Depth- First-Traversal
i). DFS is used to determine connected components of an undirected graph
ii). DFS is used to determine acyclic nature of a graph.
A :
(i)
B :
(ii)
C :
(i) and (ii)
D :
none
Answer: C
Q. No. :57
Question :The post order traversal of a binary tree is DEBFCA. Find out the pre order traversal
A :
ABFCDE
B :
ADBFEC
C :
ABDECF
D :
ABDCEF
Answer: C
Q. No. :58
Question :In a Heap tree
A :
Values in a node is greater than every value in left sub tree and smaller than right sub tree
B :
Values in a node is greater than every value in children of it
C :
Both of above conditions applies
D :
None of above conditions applies
Answer: B
Q. No. :59
Question :The elements of an array are stored successively in memory cells because
A :
by this way computer can keep track only the address of the first element and the addresses of other elements can be calculated
B :
the architecture of computer memory does not allow arrays to store other than serially
C :
both of above
D :
none of above
Answer: A
Q. No. :60
Question :A heap is
A :
Collection of waste material
B :
A complete binary tree with property that the value at each node should be as large as the value of its children.
C :
A spanning tree of order n
D :
None
Answer: B
Q. No. :61
Question :When inorder traversing a tree resulted E A C K F H D B G; the preorder traversal would return
A :
FAEKCDBHG
B :
FAEKCDHGB
C :
EAFKHDCBG
D :
FEAKDCHBG
Answer: B
Q. No. :62
Question :Stack is useful for implementing
A :
Radix sort
B :
Breadth First Search
C :
Recursion
D :
Depth First Search
Answer: C
Q. No. :63
Question :When representing any algebraic expression E which uses only binary operations in a 2-tree
A :
the variable in E will appear as external nodes and operations in internal nodes
B :
the operations in E will appear as external nodes and variables in internal nodes
C :
the variables and operations in E will appear only in internal nodes
D :
the variables and operations in E will appear only in external nodes
Answer: A
Q. No. :64
Question :In recursive implementations which of the following is true for saving the state of the steps
A :
as  full state on the stack
B :
as reversible action  on the stack
C :
both A and B
D :
None
Answer: C