#include <iostream>
using namespace std;

// Coding Questions
// Q-
// / Find the output/Error in below code snippned

class Base

{

	private:

		int var1; //4b

	protected :

		int var2;//4

	public :

		int var3;//4

        //vptr 8b

		virtual void fun1(){cout<<"Base"<<endl;}

		virtual void fun2(){cout<<"Base"<<endl;}

		void fun3(){cout<<"Base"<<endl;}

		void fun4(){cout<<"Base"<<endl;}

        void fun7(){cout<<"Base"<<endl;}

        virtual void fun8(){cout<<"Base"<<endl;}

		~Base(){cout<<"Base: Destructor"<<endl;};

};

class Derived : public Base

{

	private:

		int var4; //4

	protected :

		int var5;//4

	public :

		int var6;//4

        //plus size of base var1,var2,var3 plus vptr

		void fun1(){cout<<"Derived"<<endl;}		

		void fun3(){cout<< "Derived"<<endl;}

		virtual void fun5(){cout<< "Derived"<<endl;}

		void fun6(){cout<< "Derived"<<endl;}

        virtual void fun7(){cout<< "Derived"<<endl;}

        virtual void fun8(){cout<< "Derived"<<endl;}

		~Derived(){cout<<"Derived: Destructor";};

};

int main()

{

	Base *bPtr= new Derived();

	bPtr ->fun1();

	bPtr ->fun2();

	bPtr ->fun3();

	bPtr ->fun4();

	//bPtr ->fun5();

	//bPtr ->fun6();

    bPtr ->fun7();

    bPtr ->fun8();

	delete bPtr;

	Base obj;

	Derived der;

	cout << "\n" << sizeof(obj)<<endl;

	cout << "\n" << sizeof(der)<<endl;

}


// Q-
// // Find the output/Error in below code snippned
// int a = 10;			// Address of "a" is 0x1000
// int &ref = a;
// int *ptr= &a;		// Address of "ptr" is 0x2000
// a= 20;	
// ref  = 30;
// *ptr = 40;
// int x = 20;			// Address of "x" is 0x3000
// &ref = x;
// cout<<a<<"\t"<<ref<<"\t"<<ptr<<"\t"<<*ptr;

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: