C-Plus-Plus Questions

0 votes, 0 avg
152

C-Plus-Plus Questions

1 / 15

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

#include 
using namespace std; 
template 
T max (T &a, T &b)
{
	cout << "Template Called ";
    return (a > b)? a : b;
}
 
template <>
int max  (int &a, int &b)
{
    cout << "Called ";
    return (a > b)? a : b;
}
 
int main ()
{
    int a = 10, b = 20;
    cout << max  (a, b);
}

2 / 15

2. Consider the following given program and choose the most appropriate output from the given options:

#include   
using namespace std;   
class Base {   
public:   
    Base()     
    { cout<<"Constructing Base n"; }   
    ~Base()   
    { cout<<"Destructing Base n"; }     
};   
class Derived: public Base {   
public:   
    Derived()      
    { cout<<"Constructing Derived n"; }   
    ~Derived()   
    { cout<<"Destructing Derived n"; }   
};   
   
int main(void)   
{   
    Derived *d = new Derived();   
    Base *b = d;   
    delete b;   
    return 0;   
}  

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. Choose the type of loop which is guaranteed to execute at-least once?

5 / 15

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

6 / 15

6. Find the output of the following program.

main(){
  Float a = 5;
  switch(a){
     Case 5: cout <<”Interviewbit”;
     Default: cout <<”Scaler”;
  }
}

7 / 15

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

        }

8 / 15

8. What is Vtable?

9 / 15

9. Which of the following statement is correct about Virtual Inheritance?

10 / 15

10. 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);

        }

11 / 15

11. Which of the following can be considered as the object of an array?

12 / 15

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

13 / 15

13. What is abstract class in C++?

14 / 15

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

15 / 15

15. Which one of the following is the correct definition of the "is_array();" function in C++?

Your score is

The average score is 30%

0%