C++ quiz questions

C++ interview questions

  • 1.

    Which of the following will not return a value?

    1. null

    2. void

    3. empty

    4. free

    Answer
  • 2.

    What would be the output of the following program (in 32-bit systems)?

        #include <iostream>
        using namespace std;
        int main()
        {
            cout << sizeof(char);
            cout << sizeof(int);
            cout << sizeof(float);
            return 0;
        }

     

    1. 1 4 4

    2. 1 4 8

    3. 1 8 8

    4. none of the mentioned

    Answer
  • 3.

    What is the output of the following program?

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

     

    1. 2 6

    2. 4 6

    3. 2 5

    4. 4 5

    Answer
  • 4.

    What is the output of the following program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int num1 = 10;
            float num2 = 20;
            cout << sizeof(num1 + num2);
            return 0;
        }

     

    1. 2

    2. 4

    3. 8

    4. garbage

    Answer
  • 5.

    What is the output of the following program?

        #include <iostream>
        using namespace std;
        int main ( )
        {
            static double i;
            i = 20;
            cout << sizeof(i);
            return 0;
        }

     

    1. 4

    2. 2

    3. 8

    4. garbage

    Answer
  • 6.

    What is the output of the following program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int num = 0x20 + 020 + 20;
            cout << sizeof(num)<<'\n';
            return 0;
        }

     

    1. 2

    2. 4

    3. Depends on compiler.

    4. garbage

    Answer
  • 7.

    Identify the incorrect option.

    1. 1 <= sizeof(bool) <= sizeof(long)

    2. sizeof(float) <= sizeof(double) <= sizeof(long double)

    3. sizeof(char) <= sizeof(long) <=sizeof(wchar_t)

    4. sizeof(N) = sizeof(signed N) = sizeof(unsigned N) 

    Answer
  • 8.

    Size of C++ objects are expressed in terms of multiples of the size of a ____ and the size of a char is ____.

    1. char, 1

    2. int, 1

    3. float, 8

    4. char, 4

    Answer
  • 9.

    Implementation dependent aspects about an implementation can be found in ____

    1. <implementation>

    2. <limits>

    3. <limit>

    4. <numeric>

    Answer
  • 10.

    It is guaranteed that a ____ has atleast 8bits and a ____ has atleast 16 bits.

    1. int, float

    2. char, int

    3. bool, char

    4. char, short

    Answer
  • 11.

    The size of an object or a type can be determined using which operator?

    1. malloc

    2. sizeof

    3. malloc

    4. calloc

    Answer
  • 12.

    Which is correct with respect to size of the datatypes?

    1. char > int < float

    2. int < char > float

    3. char < int < float

    4. char < int < double

    Answer
  • 13.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            float f1 = 0.5;
            double f2 = 0.5;
            if (f1 == 0.5f)
                cout << "equal";
            else
                cout << "not equal";
            return 0;
        }

     

    1. equal

    2. not equal

    3. compile time error

    4. runtime error

    Answer
  • 14.

    Which is used to indicate single precision value?

    1. F or f

    2. L or l

    3. either a or b

    4. neither a or b

    Answer
  • 15.

    What is the output of the following program?

        #include <iostream>
        using namespace std;
        int main()
        {
            float i = 123.0f;
            cout << i << endl;
            return 0;
        }

     

    1. 123.00

    2. 1.23

    3. 123

    4. compile time error

    Answer
  • 16.

    What is the output of this program?

        #include <iomanip>
        #include <iostream>
        using namespace std;
        int main()
        {
            cout << setprecision(17);
            double d = 0.1;
            cout << d << endl;
            return 0;
        }

     

    1. 0.11

    2. 0.10000000000000001

    3. 0.100001

    4. compile time error

    Answer
  • 17.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            float num1 = 1.1;
            double num2 = 1.1;
            if (num1 == num2)
               cout << "stanford";
            else
               cout << "harvard";
            return 0;
        }

     

    1. harvard

    2. stanford

    3. compile time error

    4. runtime error

    Answer
  • 18.

    Which of three sizes of floating point types should be used when extended precision is required?

    1. float

    2. double

    3. long double

    4. extended float

    Answer
  • 19.

    What is the range of the floating point numbers?

    1. -3.4E+38 to +3.4E+38

    2. -3.4E+38 to +3.4E+34

    3. -3.4E+38 to +3.4E+36

    4. -3.4E+38 to +3.4E+32

    Answer
  • 20.

    Which of the following is a valid floating point literal?

    1. f287.333

    2. F287.333

    3. 287.e2

    4. 287.3.e2

    Answer

© 2017 QuizBucket.org