C-Plus-Plus Questions

0 votes, 0 avg
126

C-Plus-Plus Questions

1 / 15

1. A member function can always access the data in __________ , (in C++).

2 / 15

2. What will be the output of the following C++ code?

#include 
    using namespace std;
    class Box
    {   
        double length;
        double breadth;
        double height;
        public:
        double getVolume(void)
        {  
            return length * breadth * height;
        }
        void setLength( double len )
        {   
            length = len;
        }
        void setBreadth( double bre )
        {   
            breadth = bre;
        }
        void setHeight( double hei )
        {   
            height = hei;
        }
        Box operator+(const Box& b)
        {  
            Box box;
            box.length = this->length + b.length;
            box.breadth = this->breadth + b.breadth;
            box.height = this->height + b.height;
            return box;
        } 
    };
    int main( )
    {  
        Box Box1;
        Box Box2;
        Box Box3;
        double volume = 0.0;
        Box1.setLength(6.0);
        Box1.setBreadth(7.0);
        Box1.setHeight(5.0);
        Box2.setLength(12.0);
        Box2.setBreadth(13.0);
        Box2.setHeight(10.0);
        volume = Box1.getVolume();
        cout << "Volume of Box1 : " << volume <

3 / 15

3. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	cout<::type>::value;
	cout<::type>::value;
	return 0;
}

4 / 15

4. What will be the output of the following C++ code?

        #include 

        using namespace std;

        int main ()

        {

            int n;

            n = -77;

            cout.width(4); 

            cout << internal << n << endl;

            return 0;

        }

5 / 15

5. Which of the following is the correct definition of sorting?

6 / 15

6. Which of the following options correctly explains the concept of Polymorphism?

7 / 15

7. What is a binary operator?

8 / 15

8. Which option is false for the following code?

class A
{
 private : int sum(int x, int y)
 { 
  return x+y; 
 }
 public: A()
 {  
 }
 A(int x, int y)
 { 
  cout<

9 / 15

9. What will be the output of the following C++ code?

 #include 
    using namespace std;
    class number
    {
        int i;
        public:
        int geti();
        void puti(int j);
    };
    int number::geti()
    {
        return i;
    }
    void number::puti(int j)
    {
        i = j;
    }
    int main()
    {
        number s;
        s.puti(10);
        cout << s.geti( );
        return 0;
    }

10 / 15

10. what will be the output of the given program?

class base
{
public:
       base()
       {          
           cout<<"BCon";
       }
       ~base()
       {
	   cout<<"BDest ";
       }
};
class derived: public base
{
public:
       derived()
       {     cout<<"DCon ";
       }
       ~derived()
       {     cout<<"DDest ";
       }
};

int main()
{
derived object;
return 0; 
}

11 / 15

11. What will be the output of the following C++ code?

#include 
#include 
using namespace std;
int main()
{
	cout<::value;
	cout<::value;
	cout<::value;
	return 0;
}

12 / 15

12. How many times hello is printed?

int main()
{
    int i=0;
    lbl:
    cout<<"CppBuzz.com";
    i++;
    if(i<5)
    {
	goto lbl;
    }
return 0;

}

13 / 15

13. What will be the output of the following C++ code?

        #include 

        using namespace std;

        int main()

        {

            int a, b;

            int* c;

            c = &a;

            a = 200;

            b = 200;

            *c = 100;

            b = *c;

            cout << *c << " " << b;

            return 0;

        }

14 / 15

14. What is virtual inheritance in C++?

15 / 15

15. what will be the output of the following C++ code snippet?

#include
void Execute(int &x, int y = 200)
{
 int TEMP = x + y;
 x+= TEMP;
 if(y!=200)
     cout<

Your score is

The average score is 30%

0%