C Plus Plus Miscellaneous - Study Mode
[#696] What will be the output of the following C++ code? #include<iostream>
using namespace std
int main()
{
int x = 5
auto check = []() -> bool
{
if(x == 0)
return false
else
return true
}
cout<<check()<<endl
return 0
}
Correct Answer
(C) Error
[#697] What will be the output of the following C++ code? #include <iostream>
#include <vector>
using namespace std
int main()
{
vector<int> v
for (int i = 1
i <= 5
i++)
v.push_back(i)
vector<int> :: const_iterator i
i = v.begin()
*i = 3
for (i = v.begin()
i != v.end()
++i)
cout << *i << " "
cout<<endl
return 0
}
Correct Answer
(C) Error
[#698] What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex <double> cn(3.0, 5.0)
cout<<"Absolute value is: "<<abs(cn)<<endl
return 0
}
Correct Answer
(D) Absolute value is: 5.83095
[#699] What will be the output of the following C++ code? #include <iostream>
#include <typeinfo>
#include <exception>
using namespace std
class base
{
virtual void f(){}
}
class derived : public base {}
int main ()
{
try
{
base* a = new base
base* b = new derived
cout << typeid(*a).name() <v ' '
cout << typeid(*b).name()
}
catch (exception& e)
{
cout << "Exception: " << e.what() << endl
}
return 0
}
Correct Answer
(C) 4base and 7derived
[#700] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
int a
public:
virtual void func() = 0
}
class B: public A
{
public:
void func(){
cout<<"Class B"<<endl
}
}
int main(int argc, char const *argv[])
{
B b
b.func()
return 0
}
Correct Answer
(A) Class B