Monday, November 27, 2006

Yahoo Interview Questions !

1). What is the output?
main()

{
char hi[2]="HI";
cout<< hi<<' '<<"Hello";
}

Ans: It will give error. 'HI' : array bounds overflow (Because string contains '\0' implicitly. "Hi" is of length 3.
2). Write a STRING class. Implement
- default constructor,
- Copy Constructor,
- Assignment Operator,
- String length function
- String Copy function
- String concatenation,
- Destructor

3). How to find the only unique number from a list of N integers where all are duplicates except one. Find the unique number in O(n) time.

Ans: start from the first element of the array and keep XORing it with the rest of the elements saving the result.
{
j=a[0];
for(i=1;i
{
j=j^a[i];
}
printf("\n\nThe Unique is %d\n\n",j);
}

4). Design patterns in c++


Thursday, November 23, 2006

Oracle (C,C++,Unix) Interview Questions !

Few Questions from Oracle Interview :

1. How to initialize a const member variable in a class?
2. Difference between copy constructor & assignment operator.
3. Use of copy constructor.
4. How to prevent singleton class from being copied?
a. By making a private copy constructor
5. Socket programming. Description about client and server. Steps in making client and server.
6. Static and Dynamic Linking. (DLL)
7. How change the value of a const variable.
8. Different views in Rational Clearcase.
9. exec and fork system calls
10. order of Linear and Binary Search, Explain.
11. Different storage classes in c++
12. How to convert integer into String, which API to use (itoa()).
13. size of instance of A when A is
a. class A{
int I;
};
b. class A{
int I;
static int j;
};
c. class A{
int I;
virtual void print();
}
14. Explain the working (taking into account the use of virtual pointer table) :
Class A{
Int A;
Virtual void print();
};
class B{
int b;
void print();
}
main(){
A *a;
B b;
a=&b;
a->print();
}
15. Benefits of using DLLs.
16. Can static member functions use normal member variables, why or why not?
17. Use of virtual function with examples.
18. How to check for memory leak.
19. What is an inline function?
20. How are the inline functions different from macros?
21. What is the condition when compiler calls inline functions instead of replacing the function call with the function definition?
a. When we make recursive inline functions ( because compiler doesn’t knows the depth of such function call)

Ericsson Interview Questions !

Ericsson Gurgaon interview questions :


1). Merits & Demerits of
- Returning references from functions,
- Returning pointers from functions.

2). Exception handling in cpp.

3). What is wrong with the following code.
try{
int *p=new int[10];
throw int(10);
}
catch (int i){
}

3). For the following code :
Class A{
Container *someContainer;
A(){
// someContainer = new Container;
/* Write code so that if someContainer is not initialized properly
the instances of A wouldn't get created
*/
...
}
~A(){}
};

4). Questions related to Multithreading in C++

5). Questions related to signals used in Unix/Linux.

6). How to avoid multiple definitions of the same component when the same header file is included in multiple files in a the same project. (Don't use #ifdef etc preprocessor directive).

7). Difference between extern and static.

Basic funda of the interview was to test for the error handling and multithreaded skills of the candidate.