C++ quiz questions

C++ interview questions

  • 1.

    What is the output of this program?

        #include <iostream>
        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;
        }

     

    1. 2 3

    2. 6 9

    3. 2 15

    4. compile time error

    Answer
  • 2.

    What will happen when we use void in argument passing?

    1. It will not return value to its caller

    2. It will return value to its caller

    3. both a & b are correct

    4. none of the mentioned

    Answer
  • 3.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int add(int a, int b);
        int main()
        {
            int i = 5, j = 6;
            cout << add(i, j) << endl;
            return 0;
        }
        int add(int a, int b )
        {
            int sum = a + b;
            a = 7;
            return a + b;
        }

     

    1. 11

    2. 12

    3. 13

    4. compile time error

    Answer
  • 4.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        void square (int *x)
        {
    	*x = (*x + 1) * (*x);
        }
        int main ( )
        {
    	int num = 10;
            square(&num);
    	cout << num;
    	return 0;
        }

     

    1. 100

    2. compile time error

    3. 144

    4. 110

    Answer
  • 5.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        long factorial (long a)
        {
            if (a > 1)
                return (a * factorial (a + 1));
            else
                return (1);
        }
        int main ()
        {
            long num = 3;
            cout << num << "! = " << factorial ( num );
            return 0;
        }

     

    1. 6

    2. 24

    3. segmentation fault

    4. compile time error

    Answer
  • 6.

    What is the use of the indentation in c++?

    1. distinguishes between comments and code

    2. r distinguishes between comments and outer data

    3. both a and b

    4. none of the mentioned

    Answer
  • 7.

    What is used to write multi line comment in c++?

    1. /* …. */

    2. /$ …. $/

    3. //

    4. none of the mentioned

    Answer
  • 8.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            /* this is comment*
            cout << "hello world";
            return 0;
        }

     

    1. hello world

    2. hello

    3. compile time error

    4. none of the mentioned

    Answer
  • 9.

    What type of comments does c++ support?

    1. single line

    2. multi line

    3. single line and multi line

    4. none of the mentioned

    Answer
  • 10.

    What is a comment in c++?

    1. comments are parts of the source code disregarded by the compiler

    2. comments are executed by compiler to find the meaning of the comment

    3. comments are executable

    4. none of the mentioned

    Answer
  • 11.

    How many types of comments are there in c++?

    1. 1

    2. 2

    3. 3

    4. 4

    Answer
  • 12.

    Which looping process is best used when the number of iterations is known?

    1. for

    2. while

    3. do-while

    4. all looping processes require that the iterations be known

    Answer
  • 13.

    How many types of loops are there?

    1. 4

    2. 2

    3. 3

    4. 1

    Answer
  • 14.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int i;
            for (i = 0; i < 10; i++);
            {
                cout << i;
            }
            return 0;
        }

     

    1. 0123456789

    2. 10

    3. 012345678910

    4. compile time error

    Answer
  • 15.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int n = 15;
            for ( ; ;)
            cout << n;
            return 0;
        }

     

    1. error

    2. 15

    3. infinite times of printing n

    4. none of the mentioned

    Answer
  • 16.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 10;
            if (a < 15)
            {
                time:
                cout << a;
                goto time;
            }
            break;
            return 0;
        }

     

    1. 1010

    2. 10

    3. infinitely print 10

    4. compile time error

    Answer
  • 17.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main ()
        {
            int n;
            for (n = 5; n > 0; n--)
            {
                cout << n;
                if (n == 3)
                    break;
            }
            return 0;
        }

     

    1. 543

    2. 54

    3. 5432

    4. 53

    Answer
  • 18.

    The destination statement for the goto label is identified by what label?

    1. $

    2. @

    3. *

    Answer
  • 19.

    The switch statement is also called as?

    1. choosing structure

    2. selective structure

    3. certain structure

    4. none of the mentioned

    Answer
  • 20.

    The if..else statement can be replaced by which operator?

    1. Bitwise operator

    2. Conditional operator

    3. Multiplicative operator

    4. none of the mentioned

    Answer

© 2017 QuizBucket.org