Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ Constants & Data Types MCQ | Set 3

C++ Constants & Data Types | Set 3


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

a) CHAR_SIZE
b) SIZE_CHAR
c) BIT_CHAR
d) CHAR_BIT



22. The size_t integer type in C++ is?

a) Unsigned integer of at least 64 bits
b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits
d) Signed integer of at least 64 bits



23. What will be the output of the following C++ code?
#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: " ;
    }
    return 0;
}

a) x is greater
b) y is greater
c) implementation defined
d) arbitrary



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

a) (v | (v + 1)) == 0;
b) (~v & (v – 1)) == 0;
c) (v | (v – 1)) == 0;
d) (v & (v – 1)) == 0;



25. What is the value of the following 8-bit integer after all statements are executed?
1. int x = 1;
2. x = x << 7;
3. x = x >> 7;

a) 1
b) -1
c) 127
d) Implementation defined



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

a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+2)



27. Which of these expressions will isolate the rightmost set bit?

a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)



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

a) decimal, character, octal, hexadecimal
b) octal, hexadecimal, character, decimal
c) hexadecimal, octal, decimal, character
d) octal, decimal, character, hexadecimal



29. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
    int x = 8;
        cout << "ANDing integer 'x' with 'true' : " << x && true;
    return 0;
}

a) ANDing integer ‘x’ with ‘true’ :8
b) ANDing integer ‘x’ with ‘true’ :0
c) ANDing integer ‘x’ with ‘true’ :1
d) ANDing integer ‘x’ with ‘true’ :9



30. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
    int i = 3;
    int l = i / -2;
    int k = i % -2;
        cout << l << k ;
    return 0;
}

a) compile time error
b) -1 1
c) 1 -1
d) implementation defined



- Related Topics