C-Plus-Plus Questions

0 votes, 0 avg
233

C-Plus-Plus Questions

1 / 15

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

2 / 15

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

3 / 15

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

4 / 15

4. What is the output of this C++ program in the “test.txt” file?

        #include 

        using namespace std;

        int main ()

        {

            long pos;

            ofstream outfile;

            outfile.open ("test.txt");

            outfile.write ("This is an apple",16);

            pos = outfile.tellp();

            outfile.seekp (pos - 7);

            outfile.write (" sam", 4);

            outfile.close();

            return 0;

        }

5 / 15

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

#include 
using namespace std;
void square (int *x, int *y)
{
	*x = (*x) * --(*y);
}
int main ( )
{
	int number = 30;
	square(&number, &number);
	cout << number;
	return 0;
}

6 / 15

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

7 / 15

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

8 / 15

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

#include 
    using namespace std;
    int main()
    {
        int a = 5;
        float b;
        cout << sizeof(++a + b);
        cout << a;
        return 0;
    }

9 / 15

9. Which of the following constructors are provided by the C++ compiler if not defined in a class?

10 / 15

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

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

13 / 15

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

14 / 15

14. Find the output of below program.

int main()
{
for(int i=1;i<=2;i++)
{
for(int j=i;j<=2;j++)
cout<

15 / 15

15. Which of the following is used for comments in C++?

Your score is

The average score is 32%

0%

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

Scroll to Top