Can destructor be private?
Dec 9th
Yes destructors can be private. But according to Standard Programming practice it is not advisable to have destructors to be private.
How can double dimensional arrays be dynamically initialized in C++?
Dec 9th
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
What is the difference between macro and inline()?
Dec 9th
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.
Why always array starts with index 0
Dec 9th
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.
What is the difference betwen wait() and delay()?
Dec 9th
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 <dos.h> while one can directly use wait in his/her program.
What is the difference between Object and Instance?
Dec 9th
An instance of a user-defined type (i.e., a class) is called an object. We can instantiate many objects from one class. An object is an instance or occurrence of a class.
Why cant one make an object of abstract class?Give compiler view of statement?
Dec 9th
we cant make object of abstract class becoz, in the vtable the vtable entry for the abstract class functions will be NULL, which ever are defined as pure virtual functions… even if there is a single pure virtual function in the class the class becomes as abstract class.. if there is a virtual function in your class the compiler automatically creates a table called virtual function table .. to store the virtual function addresses…. if the function is a pure virtual function the vtable entry for that function will be NULL. even if there is a single NULL entry in More >
Which one of two should we prefer always and why?
Dec 9th
In first case a variable will be create in memeory with the default base type value (depending upon compiler 2 compiler) bcoz it is not initialized. in second case the variable will be created in the memory with the value retuned by the function int() (if int is a user define function) the second statement should have been int *i = new int();
What is a memory leak? How can we avoid it?
Dec 9th
A memory leak can be avoided by making sure that whatever memory has been dynamically allocated will be cleared after the use of the same. for example
int main()
{ char *myCharData[20];
for (int nLoop =0;nLoop < 20; ++nLoop) { myCharData[nLoop ] = new char[256];
strcpy(myCharData[nLoop],”SABITH”); …… } …………………… /*Some manipulations here using myCharData*/ /*Now here we have to clear the data. The place can vary according to ur program. This being a simple program,u can clear at the end*/ for(int nLoop =0;nLoop < 20; ++nLoop) {
delete[] myCharData[nLoop ];
} return 0;