C-Plus-Plus Questions

0 votes, 0 avg
221

C-Plus-Plus Questions

1 / 15

1. Which of the following statements is correct about the formal parameters in C++?

2 / 15

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

3 / 15

3. How many times ‘its a while loop’ should be printed?

int main()
{
int i = 1 ;
i = i - 1 ;

while(i)
{
    cout<<"its a while loop";
    i++ ;
}

return 0;
}

4 / 15

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

5 / 15

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

#include 
    #include
    using namespace std;
    int main ()
    {
        int array[] = {0, 2, 4, 6, 7, 5, 3};
        int n, result = 0;
        for (n = 0; n < 8; n++) 
        {
            result += array[n];
        }
        cout << result;
        return 0;
    }

6 / 15

6. What is virtual inheritance in C++?

7 / 15

7. Among the following, which statement is correct about the Modularity?

8 / 15

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

        }

9 / 15

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

        #include 

        using namespace std;

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

        {

            a *= 2;

            b *= 2;

            c *= 2;

        }

        int main ()

        {

            int x = 1, y = 3, z = 7;

            copy (x, y, z);

            cout << "x =" << x << ", y =" << y << ", z =" << z;

            return 0;

        }

10 / 15

10. Which of the following loops is best when we know the number of iterations?

11 / 15

11. Which of the following is not a type of inheritance?

12 / 15

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

13 / 15

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

14 / 15

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

        }

15 / 15

15. Observer the given C++ program carefully and choose the correct output from the given options:

#include   
#include   
using namespace std;  
int main()  
{  
    cout<::value; // case A  
    cout<::value; // case B  
    cout<::value;  // case c  
    return 0;  
}  

Your score is

The average score is 33%

0%

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