Set - 4

Question 1 :

What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

Answer :

An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object.

Question 2 :

What is a scope resolution operator?

Answer :

A scope resolution operator (::), can be used to define the member functions of a class outside the class.

Question 3 :

What do you mean by pure virtual functions? 

Answer :

A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.

class Shape { public: virtual void draw() = 0; };


Question 4 :

What is polymorphism? Explain with an example? 

Answer :

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.
Example: function overloading, function overriding, virtual functions. Another example can be a plus '+' sign, used for adding two integers or for using it to concatenate two strings.

Question 5 :

What's the output of the following program? Why?

Answer :

#include <stdio.h>
	typedef union{
		int a;
		char b[10];
		float c;

	Union x,y = {100};
	x.a = 50;
	x.c = 21.50;

	printf(\"Union x : %d %s %f \n\",x.a,x.b,x.c );
	printf(\"Union y :%d %s%f \n\",y.a,y.b,y.c);

Given inputs X, Y, Z and operations | and & (meaning bitwise OR and AND, respectively)
What is output equal to in

output = 

(X & Y) | (X & Z) | (Y & Z)