C-Plus-Plus Questions

0 votes, 0 avg
39

C-Plus-Plus Questions

1 / 15

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

        }

2 / 15

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

#include 
#include 
using namespace std;
class Box
{
	int capacity;
    public:
	Box(int cap){
		capacity = cap;
	}
 
	friend void show();
};
 
void show()
{	
	Box b(10);
	cout<<"Value of capacity is: "<

3 / 15

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

4 / 15

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

5 / 15

5. Which of the following is correct about this pointer in C++?

6 / 15

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

        }

7 / 15

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

        }

8 / 15

8. What is a binary operator?

9 / 15

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

10 / 15

10. What is abstract class in C++?

11 / 15

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

12 / 15

12. Under which pillar of OOPS does base class and derived class relationship come?

13 / 15

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

#include 
    using namespace std;
    class Box
    {
        public :
        double length;
        double breadth;
        double height;
    };
    int main( )
    {
        Box Box1;
        double volume;
        Box1.height = 5;
        Box1.length = 6;
        Box1.breadth = 7.1;
        volume = Box1.height * Box1.length * Box1.breadth;
        cout << "Volume of Box1 : " << volume <

14 / 15

14. Find output of below program

int main()
{
int c1,c2;
int a = -8;
int b = 3;
c1 = --a + b;
c2 = a-- + b;
cout<<"c1="<
                        
                        
                        
                        
                    

15 / 15

15. dentify the correct definition of ‘*’ operator in pointer.

Your score is

The average score is 22%

0%