C++ quiz questions

C++ interview questions

  • 1.

    Which of the following is not one of the sizes of the floating point types?

    1. short float

    2. float

    3. long double

    4. double

    Answer
  • 2.

    What will be output of this function?

        int main()
        {
            register int i = 1;
            int *ptr = &i;
            cout << *ptr;
    	return 0;
        }

     

    1. 0

    2. 1

    3. Compiler error may be possible

    4. Runtime error may be possible

    Answer
  • 3.

    What will be output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int i = 3;
            int l = i / -2;
            int k = i % -2;
            cout << l << k;
            return 0;
        }

     

    1. compile time error

    2. -1 1

    3. 1 -1

    4. implementation defined

    Answer
  • 4.

    What will be the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 8;
            cout << "ANDing integer 'a' with 'true' :" << a && true;
            return 0;
        }

     

    1. ANDing integer ‘a’ with ‘true’ :8

    2. ANDing integer ‘a’ with ‘true’ :0

    3. ANDing integer ‘a’ with ‘true’ :1

    4. None of the mentioned

    Answer
  • 5.

    0946, 786427373824, ‘x’ and 0X2f are _____, _____, ____ and _____ literals respectively

    1. decimal, character,octal, hexadecimal

    2. octal, hexadecimal, character, decimal

    3. hexadecimal, octal, decimal, character

    4. octal, decimal, character, hexadecimal

    Answer
  • 6.

    Which of these expressions will isolate the rightmost set bit?

    1. x = x & (~x)

    2. x = x ^ (~x)

    3. x = x & (-x)

    4. x = x ^ (-x)

    Answer
  • 7.

    Which of these expressions will make the rightmost set bit zero in an input integer x?

    1. x = x | (x-1)

    2. x = x & (x-1)

    3. x = x | (x+1)

    4. x = x & (x+1)

    Answer
  • 8.

    What is the value of the following 8-bit integer after all statements are executed?

    int x = 1;
    x = x << 7;
    x = x >> 7;

    1. 1

    2. -1

    3. 127

    4. Implementation defined

    Answer
  • 9.

    Which of these expressions will return true if the input integer v is a power of two?

    1. (v | (v + 1)) == 0;

    2. (~v & (v – 1)) == 0;

    3. (v | (v – 1)) == 0;

    4. (v & (v – 1)) == 0;

    Answer
  • 10.

    What is the output of the following program?

        #include <iostream>
        using namespace std;
        int main()
        {
        	int x = -1;
            unsigned int y = 2;
     
            if(x > y) {
            	cout << "x is greater";
        	} else {
        		cout << "y is greater";
        	}
        }

     

    1. x is greater

    2. y is greater

    3. Implementation defined

    4. Arbitrary

    Answer
  • 11.

    The size_t integer type in C++ is?

    1. Unsigned integer of at least 64 bits

    2. Signed integer of at least 16 bits

    3. Unsigned integer of at least 16 bits

    4. Signed integer of at least 64 bits

    Answer
  • 12.

    What constant defined in <climits> header returns the number of bits in a char?

    1. CHAR_SIZE

    2. SIZE_CHAR

    3. BIT_CHAR

    4. CHAR_BIT

    Answer
  • 13.

    Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?

    1. 4

    2. 1

    3. Implementation dependent

    4. Machine dependent

    Answer
  • 14.

    Is the size of character literals different in C and C++?

    1. Implementation defined

    2. Can’t say

    3. Yes, they are different

    4. No, they are not different

    Answer
  • 15.

    In C++, what is the sign of character data type by default?

    1. Signed

    2. Unsigned

    3. Implementation dependent

    4. None of these

    Answer
  • 16.

    What is the output of this program?

        #include <stdio.h>
        int main()
        {
            char a = '\012';
     
            printf("%d", a);
            return 0;
        }

     

    1. Compiler error

    2. 12

    3. 10

    4. Empty

    Answer
  • 17.

    How do we represent a wide character of the form wchar_t?

    1. L’a’

    2. l’a’

    3. L[a] d) la

    Answer
  • 18.

    What will be the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            char c = 74;
            cout << c;
            return 0;
        }

     

    1. A

    2. N

    3. J

    4. I

    Answer
  • 19.

    Which of the following belongs to the set of character types?

    1. char

    2. wchar_t

    3. only a

    4. both a and b

    Answer
  • 20.

    Select the right option.
    Given the variables p, q are of char type and r, s, t are of int type
    1. t = (r * s) / (r + s);
    2. t = (p * q) / (r + s);

    1. 1 is true but 2 is false

    2. 1 is false and 2 is true

    3. both 1 and 2 are true

    4. both 1 and 2 are false

    Answer

© 2017 QuizBucket.org