C++ Interview Questions Part 2

C++ interview question :what is the difference betwen wait() and delay()?
Answer :Wait() and delay() works same but works on different platforms. Wait(2) will wait processing fro 2 second on Linux/Unix while delay(2000) with wait for 2 second but on DOS or Windows. so wait(2) on linux == delay(2000) on DOS Delay() is under while one can directly use wait in his/her program. 

C++ interview question :Why always array starts with index 0
Answer :Array name is a constant pointer pointing to the base address(address of the first byte where the array begin) of the memory allocated. When you use arr[i], the compiler manipulates it as *(arr + i). Since arr is the address of the first element, the value of i must be 0 for accessing it. Hence all arrays begin with an index of 0. 

C++ interview question: Can main() be overridden 
Answer : In any application, there can be only one main function. In c++, main is not a member of any class. There is no chance of overriding 

C++ interview question :What is the difference between macro and inline()? 
Answer :
1. Inline follows strict parameter type checking, macros do not.
2. Macros are always expanded by preprocessor, whereas compiler may or may not replace the inline definitions. 

C++ interview question: How can double dimensional arrays be dynamically initialized in C++?
Answer :example of how to dynamically initialize double dimensional arrays:
int num[2][3] = {34,32,30,24,22,20};
num[1][1] = 34
num[1][2] = 32
num[1][3] = 30
num[2][1] = 24
num[2][2] = 22
num[2][3] = 20 

C++ interview question: Can destructor be private?
Answer: Yes destructors can be private. But according to Standard Programming practice it is not advisable to have destructors to be private.

0 comments:

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP