C-Plus-Plus Questions

0 votes, 0 avg
44

C-Plus-Plus Questions

1 / 15

1. What is the correct definition of an array?

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. How many times hello is printed?

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

}

4 / 15

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

#include 
    using namespace std;
    int main()
    {
        int a = 5;
        float b;
        cout << sizeof(++a + b);
        cout << a;
        return 0;
    }

5 / 15

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

6 / 15

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

        #include 

        using namespace std;

        void square (int *x)

        {

    	*x = (*x + 1) * (*x);

        }

        int main ( )

        {

    	int num = 10;

            square(&num);

            cout << num; 

            return 0;

        }

7 / 15

7. Which is more effective while calling the C++ functions?

8 / 15

8. Would destructor be called, if yes, then due to which vector?

#include 
#include 
using namespace std;
 
class a
{
public :
    ~a()
    {
        cout << "destroy";
    }
};
int main()
{
   vector  *v1  = new vector;
   vector  *v2  = new vector;
   return 0;
}