C-Plus-Plus Questions

0 votes, 0 avg
244

C-Plus-Plus Questions

1 / 15

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

2 / 15

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

#include 
using namespace std;

class X
{
public: X()
        { cout<<"X"; }
        ~X()
        { cout<<"~X"; }
};

class Y : public X
{
public: Y()
        { cout<<"Y"; }
        ~Y()
        { cout<<"~Y"; }
};

int main()
{
    Y obj;
    return 0;
}

3 / 15

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

#include 
using namespace std; 
template 
int arrMin(T arr[], int n)
{
   int m = max;
   for (int i = 0; i < n; i++)
      if (arr[i] < m)
         m = arr[i];
 
   return m;
}
 
int main()
{
   int arr1[]  = {10, 20, 15, 12};
   int n1 = sizeof(arr1)/sizeof(arr1[0]);
 
   char arr2[] = {1, 2, 3};
   int n2 = sizeof(arr2)/sizeof(arr2[0]);
 
   cout << arrMin(arr1, n1) << endl;
   cout << arrMin(arr2, n2);
   return 0;
}

4 / 15

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

        }

5 / 15

5. What is dangling pointer?

6 / 15

6. How can one implement the run-time Polymorphism in the C++ programming language?

7 / 15

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

8 / 15

8. Pick the incorrect statement about Character-Array.

9 / 15

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

10 / 15

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

11 / 15

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

12 / 15

12. What is the output of the given program?

#include < stdio.h >  
using namespace std;  
int main()  
{  
int array[] = {10, 20, 30};  
cout << -2[array];  
return 0;  
}  

13 / 15

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

14 / 15

14. Consider the following given program and choose the most appropriate output from the given options:

#include   
using namespace std;  
class A{  
public:  
    A(){  
        cout<<"Constructor calledn";  
       }  
    ~A(){  
        cout<<"Destructor calledn";  
        }   
};  
int main(int argc, char const *argv[])  
{  
    A *a = new A[5];  
    delete[] a;  
    return 0;  
}  

15 / 15

15. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is ____________

Your score is

The average score is 32%

0%

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

Scroll to Top