C-Plus-Plus Questions

0 votes, 0 avg
211

C-Plus-Plus Questions

1 / 15

1. What is the use of is_same() function in C++?

2 / 15

2. Choose the type of loop which is guaranteed to execute at-least once?

3 / 15

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

#include 
using namespace std;

class X
{
public: X()
        { cout<<"X"; }
        ~X()
        { cout<<"~X"; }
};

class Y : public X
{
public: Y()
        { cout<<"Y"; }
        ~Y()
        { cout<<"~Y"; }
};

int main()
{
    Y obj;
    return 0;
}

4 / 15

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

        #include 

        using namespace std;

        void Sum(int a, int b, int & c)

        {

            a = b + c;

            b = a + c;

            c = a + b;

        }

        int main()

        {

            int x = 2, y =3;

            Sum(x, y, y);

            cout << x << " " << y;

            return 0; 

        }

                            

5 / 15

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

 #include 
    using namespace std;
    class Rect
    {
        int x, y;
        public:
        void set_values (int,int);
        int area ()
        {
            return (x * y);
        }
    };
    void Rect::set_values (int a, int b) 
    {
        x = a;
        y = b;
    }
    int main ()
    {
        Rect recta, rectb;
        recta.set_values (5, 6);
        rectb.set_values (7, 6);
        cout << "recta area: " << recta.area();
        cout << "rectb area: " << rectb.area();
        return 0;
    }

6 / 15

6. Choose the correct option which is mandatory in a function.

7 / 15

7. What is abstract class in C++?

8 / 15

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

#include 
    using namespace std;
    void swap(int &a, int &b);
    int main()
    {
        int a = 5, b = 10;
        swap(a, b);
        cout << "In main " << a << b;
        return 0;
    }
    void swap(int &a, int &b)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
        cout << "In swap " << a << b;
    }

9 / 15

9. Pick the incorrect statement about inline functions in C++?

10 / 15

10. What is virtual inheritance in C++?

11 / 15

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

 #include 
    using namespace std;
    class myclass
    {
        public:
        int i;
        myclass *operator->()
        {return this;}
    };
    int main()
    {
        myclass ob;
        ob->i = 10; 
        cout << ob.i << " " << ob->i;
        return 0;
    }

12 / 15

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

        #include 

        using namespace std;

        int gcd (int a, int b)

        {

            int temp;

            while (b != 0) 

            {

                temp = a % b;

                a = b;

                b = temp;

            }

            return(a);

        }

        int main ()

        {

            int x = 15, y = 25;

            cout << gcd(x, y);

            return(0);

        }

13 / 15

13. How many times hello is printed?

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

}

14 / 15

14. 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;
}

15 / 15

15. What are Distributions in C++?

Your score is

The average score is 32%

0%