- What is Association and navigability?
2. What is the benefit of using static data members?
Static data asides only one place in memory it does not matter how many objects are created for that class. The basic use of a static data member to count how many objects are created in that class. We must separate declaration and definition of static data like in the class we must declare it by saying <static int count:>. While we must define it outside the class by saying <int foo :: count=0;>. Otherwise the linker will complain
3. What is the difference between delete and destructor?
delete operator deletes a dynamically allocated object in memory which calls destructor to de-initialize that object.
4.What happens when we use delete twice for a dynamically allocated object?
If we delete twice a dynamically allocated object then it will corrupt heap.
5. Which function will be called if we write sample (10); in the calling program?
Sample(int i,int j=12);
Sample(int i);
It leads a compiler error as ambiguity occurs during function call.
Sample(int i);
It leads a compiler error as ambiguity occurs during function call.
6. What is difference between delete arr & delete [] arr fro an array of objects?
delete arr deletes complete array but calls destructor for first element where as delete [] deletes complete array as well as calls destructor for each element.
delete arr deletes complete array but calls destructor for first element where as delete [] deletes complete array as well as calls destructor for each element.
7. Can a programmer give guaranty that register variables will be stored in CPU register?
When a programmer declares a variable of register type there is no guaranty that it will be stored in CPU register. Its completely depends on compiler and available space in CPU register.
8. Tell me at least three ways to access private data members from outside of a class?
There are various ways to access private data members in a class
8. Tell me at least three ways to access private data members from outside of a class?
There are various ways to access private data members in a class
- We can define a public member function in that class through which can easily access private data members.
- Store the address of the object in a pointer, pointer should be int type. So while storing the address of the object we need to explicitly typecast it. After storing the address of the object we can easily access private data.
- Using friend function we can access private data member of a class.
No comments:
Post a Comment