What is the difference between class and structure?

1:By default, the members of structures are public while that for class is private

2: structures doesn’t provide something like data hiding which is provided by the classes

3: structures contains only data while class bind both data and member functions

We can overload assignment operator as a normal function.But we can not overload assignment operator as friend function why?

If the operation modifies the state of the class object, it operates on, it must be a member function, not a friend fucntionThus all operator such as =, *=, +=, etc are naturally defined as member functions not friend functions Conversely, if the operator does not modify any of its operands, but needs only a representation of the object, it does not have to be a member function and often less confusing. This is the reason why binary operators are often implemented as friend functions such as + , *, -, etc..

What are virtual functions?

C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. C++ virtual function is, * A member function of a class * Declared with virtual keyword * usually has a different functionality in the derived class * A function call is resolved at run-time

What is the Basic nature of “cin” and “cout” and what concept or principle we are using on those two?

Basically “cin and cout” are INSTANCES of istream and ostream classes respectively. And the concept which is used on cin and cout is operator overloading. Extraction and Insertion operators are overloaded for input and ouput operations.

What is the difference between operator new and the new operator?

This is what happens when you create a new object: 1. the memory for the object is allocated using “operator new”. 2. the constructor of the class is invoked to properly initialize this memory. As you can see, the new operator does both 1 and 2. The operator new merely allocates memory, it does not initialize it. Where as the new operator also initializes it properly by calling the constructor.

How can you force instantiation of a template?

you can instantiate a template in two ways. 1. Implicit instantiation and 2. Explicit Instantion. implicit instatanitioan can be done by the following ways:

template <class T>

class A

{

public:

A(){}

~A(){}

void x();

void z();

};

void main()

{

A<int> ai;

A<float> af;

}

External Instantion can be done the following way:

int main()

{

template class A<int>;

template class A<float>;

}

# what is an algorithm (in terms of the STL/C++ standard library)?

Algorithm in STL consist different searching and sorting algos implementation, which takes start and end iterators of STL container on which algo is going to work.

What is the output of printf (“%d”)

Usually the output value cannot be predicted. It will not give any error. It will print a garbage value. But if the situation is main() { int a=1,b=2,c=3; printf(“%d”); } The output will be the value of the last variable, ie. 3

What will happen if I say delete “Virtual Destructor”.?

if you say “delete this”, you are effectively calling the destructor twice, which could well be a disaster if your class uses heap. The destructor will be called when you say “delete this” and again when that object goes out of scope. Since this is the language behavior, there is no way to prevent the destructor from being called twice. Please refrain from forcibly calling a destructor or using clause like this.

Can we have “Virtual Constructors”?

No, we cannot have virtual constructors. But if the need arises, we can simulate the implementation of virtual constructor by calling a Init method from the constructor which, should be a virtual function.