C-Plus-Plus Questions

0 votes, 0 avg
19

C-Plus-Plus Questions

1 / 15

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

  #include 
   using namespace std;
   int main()
   {
       int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
       return 0;
   }

2 / 15

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

3 / 15

3. How structures and classes in C++ differ?

4 / 15

4. Predict the output of following C++ program.

#include
using namespace std;
 
union A {
  int a;
  unsigned int b;
  A() { a = 10; }
  unsigned int getb() {return b;}
};
 
int main()
{
    A obj;
    cout << obj.getb();
    return 0;
}

5 / 15

5. By which of the following can the if-else statement be replaced?

6 / 15

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

7 / 15

7. What is the correct definition of an array?

8 / 15

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

#include
using namespace std;
 
class Test
{
  protected:
    int x;
  public:
    Test (int i):x(i) { }
    void fun() const  { cout << "fun() const " << endl; }
    void fun()        {  cout << "fun() " << endl;     }
};
 
int main()
{
    Test t1 (10);
    const Test t2 (20);
    t1.fun();
    t2.fun();
    return 0;
}

9 / 15

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

#include
using namespace std;
int main()
{
	int a = 5;
	auto check = [=]() 
        {
		a = 10;
	};
	check();
	cout<<"Value of a: "<

10 / 15

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

        }

11 / 15

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

        }

12 / 15

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

        #include 

        using namespace std;

        int main()

        {

            int a, b;

            int* c;

            c = &a;

            a = 200;

            b = 200;

            *c = 100;

            b = *c;

            cout << *c << " " << b;

            return 0;

        }

13 / 15

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

14 / 15

14. Which concept allows you to reuse the written code in C++?

15 / 15

15. Pick the incorrect statement about inline functions in C++?

Your score is

The average score is 16%

0%