C Plus Plus Miscellaneous - Study Mode
[#731] What will be the output of the following C++ code? #include <iostream>
#include <bitset>
using namespace std
int main()
{
bitset<8> b1(20)
cout<<b1.none()
cout<<b1.any()
}
Correct Answer
(A) 01
[#732] What will be the output of the following C++ code? #include <iostream>
using namespace std
void PrintSequence(int StopNum)
{
int Num
Num = 1
while (true)
{
if (Num >= StopNum)
throw Num
cout << Num << endl
Num++
}
}
int main(void)
{
try
{
PrintSequence(2)
}
catch(int ExNum)
{
cout << "exception: " << ExNum << endl
}
return 0
}
Correct Answer
(C) 1 exception: 2
[#733] What will be the output of the following C++ code? #include <iostream>
using namespace std
class BaseClass
{
int i
public:
void setInt(int n)
int getInt()
}
class DerivedClass : public BaseClass
{
int j
public:
void setJ(int n)
int mul()
}
void BaseClass::setInt(int n)
{
i = n
}
int BaseClass::getInt()
{
return i
}
void DerivedClass::setJ(int n)
{
j = n
}
int DerivedClass::mul()
{
return j * getInt()
}
int main()
{
DerivedClass ob
ob.setInt(10)
ob.setJ(4)
cout << ob.mul()
return 0
}
Correct Answer
(C) 40
[#734] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main ()
{
try
{
throw 20
}
catch (int e)
{
cout << "An exception occurred " << e << endl
}
return 0
}
Correct Answer
(D) An exception occurred 20
[#735] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main ()
{
int n
n = 43
cout << hex << n << endl
return 0
}
Correct Answer
(B) 2b