C-Plus-Plus Questions

0 votes, 0 avg
223

C-Plus-Plus Questions

1 / 15

1. Which part of memory is used for the allocation of local variables declared inside any function.

2 / 15

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

3 / 15

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

        #include 

        #include 

        #include 

        using namespace std;

        int main ()

        {

            string mystr;

            float price = 0;

            int quantity = 0;

            cout << "Enter price: ";

            getline (cin, mystr);

            stringstream(mystr) >> price;

            cout << "Enter quantity: ";

            getline (cin, mystr);

            stringstream(mystr) >> quantity;

            cout << "Total price: " << price * quantity << endl;

            return 0;

        }

4 / 15

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

5 / 15

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

int main() 
{
int i=0,x=0;

for(i=1;i<10;i*=2)
{
    x++;
    cout<

6 / 15

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

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.