What will be the output of the following C++ code? [code] #include <iostream> #include <bitset> using namespace std; int main() { bitset<8>

Như Quỳnh

New member
What will be the output of the following C++ code?
Code:
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
	bitset<8> b1(15);
	cout<<b1;
}
A. 00001111
B. 1111
C. 11110000
D. 0000000000001111
 
Answer: a
Explanation: As the size provided to bitset variable is 8, therefore, the number of bits that this variable will have is equal to 8. Now as 15 is 1111 so the least most significant digits will be 1111 to make it represent 15. Hence the answer is 00001111.
 

Tìm kiếm

Back
Top