C Plus Plus Miscellaneous - Study Mode
[#686] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int a = 10
if (a < 15)
{
time:
cout << a
goto time
}
break
return 0
}
Correct Answer
(D) compile time error
[#687] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
int num = 3
string str_bad = "wrong number used"
try
{
if ( num == 1 )
{
throw 5
}
if ( num == 2 )
{
throw 1.1f
}
if ( num != 1 || num != 2 )
{
throw str_bad
}
}
catch (int a)
{
cout << "Exception is: " << a << endl
}
catch (float b)
{
cout << "Exception is: " << b << endl
}
catch (...)
{
cout << str_bad << endl
}
return 0
}
Correct Answer
(C) Wrong number used
[#688] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <tuple>
using namespace std
int main()
{
tuple <int, char, string> tp1
tuple <int, char, string> tp2
tp1 = make_tuple(6, 'a', "Hello")
tp2 = make_tuple(9, 'z', "World")
cout<<"("<<get<0>(tp1)<<", "<<get<1>(tp1)<<", "<<get<2>(tp1)<<")"<<endl
cout<<"("<<get<0>(tp2)<<", "<<get<1>(tp2)<<", "<<get<2>(tp2)<<")"<<endl
tp1.swap(tp2)
cout<<"("<<get<0>(tp1)<<", "<<get<1>(tp1)<<", "<<get<2>(tp1)<<")"<<endl
cout<<"("<<get<0>(tp2)<<", "<<get<1>(tp2)<<", "<<get<2>(tp2)<<")"<<endl
return 0
}
Correct Answer
(A) (6, a, Hello) (9, z, World) (9, z, World) (6, a, Hello)
[#689] What will be the output of the following C++ code? #include <iostream>
#include <vector>
#include <algorithm>
using namespace std
int main(int argc, char const *argv[])
{
vector <int> v = {1,5,23,90,15,35}
make_heap(v.begin(),v.end())
cout<<v.front()
}
Correct Answer
(A) 23
[#690] Which is the following is syntactically correct for vector<int> v?
Correct Answer
(C) vector <int> :: iterator itr = v.begin()