C-Plus-Plus Questions

0 votes, 0 avg
221

C-Plus-Plus Questions

1 / 15

1. Find output of below program

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

2 / 15

2. When will we use the function overloading?

3 / 15

3. Which option is false for the following code?

class A
{
 private : int sum(int x, int y)
 { 
  return x+y; 
 }
 public: A()
 {  
 }
 A(int x, int y)
 { 
  cout<

4 / 15

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

        #include 

        using namespace std;

        int main () 

        {

            int n; 

            n = 43;

            cout << hex << n << endl;

            return 0;

        }

5 / 15

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

6 / 15

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

#include 
    using namespace std;
    void swap(int &a, int &b);
    int main()
    {
        int a = 5, b = 10;
        swap(a, b);
        cout << "In main " << a << b;
        return 0;
    }
    void swap(int &a, int &b)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
        cout << "In swap " << a << b;
    }

7 / 15

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

8 / 15

8. What should be printed on screen?

int main() 
{
int x = 5;

if(x++ == 5)
cout<<"Five"<

9 / 15

9. Which of the following is the correct syntax of including a user defined header files in C++?

10 / 15

10. What is Pseudo-random number engines?

11 / 15

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

12 / 15

12. Where does the return statement returns the execution of the program?

13 / 15

13. Choose the correct option which is mandatory in a function.

14 / 15

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

15 / 15

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

        }

Your score is

The average score is 33%

0%

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