Tech Mahindra Technical Interview Questions

1. What is the output of the following program?
class complex{
double re;
double im;
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout«re; cout«im;}

void main(){
complex c3;
double i=5;
c3 = i;

a) 4,5 b) 3,5 c) 5,5 d) None of the above

2. What is the error in the class declaration?
class something
char *str;
st = new char[10]; }
delete str;

a) pointer not defined
b) st not defined
c) deleting a pointer is wrong
d) None of the above

3. Find the error in the class declaration?
class temp
int value1;
mutable int value2;
public :
void fun(int val)
((temp*) this)->value1 = 10;
value2 = 10;

a) mutable is wrongly used
b) const is not a function
c) wrong use of pointer
d) None of the above

4. What is spanning tree?
5. Explain traveling salesman problem?
6. What is the difference between BFS and DFS?
7. Write down the prim’s algorithm?
8. What is JVM? What is its use?
9. How to do memory management in JAVA?
10. Why are constructors and destructors used?

Shared by: Susant Kumar