C-Plus-Plus Questions

0 votes, 0 avg
225

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, b;

            int* c;

            c = &a;

            a = 200;

            b = 200;

            *c = 100;

            b = *c;

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

            return 0;

        }

2 / 15

2. Identify the correct syntax for declaring arrays in C++.

3 / 15

3. Which of the following is correct about friend functions?

4 / 15

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

        #include 

        using namespace std;

        void Sum(int a, int b, int & c)

        {

            a = b + c;

            b = a + c;

            c = a + b;

        }

        int main()

        {

            int x = 2, y =3;

            Sum(x, y, y);

            cout << x << " " << y;

            return 0; 

        }

                            

5 / 15

5. 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: "<

6 / 15

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

 #include 
    using namespace std;
    class number
    {
        int i;
        public:
        int geti();
        void puti(int j);
    };
    int number::geti()
    {
        return i;
    }
    void number::puti(int j)
    {
        i = j;
    }
    int main()
    {
        number s;
        s.puti(10);
        cout << s.geti( );
        return 0;
    }

7 / 15

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

8 / 15

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

9 / 15

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

10 / 15

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

int main() 
{
int i=0,x=0;

for(i=1;i<10;i*=2)
{
    x++;
    cout<

11 / 15

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

        }

12 / 15

12. What did we call an array of the one-dimensional array?

13 / 15

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

#include
void Execute(int &x, int y = 200)
{
 int TEMP = x + y;
 x+= TEMP;
 if(y!=200)
     cout<

14 / 15

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

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 32%

0%

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

Scroll to Top