C Plus Plus Miscellaneous - Study Mode
[#906] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int var = -12
try {
cout<<"Inside try
"
if (var < 0)
{
throw var
cout<<"After throw
"
}
}
catch (char var ) {
cout<<"Exception Caught
"
}
cout<<"After catch
"
return 0
}
Correct Answer
(D) Run-time error
[#907] What will be the output of the following C++ code? #include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std
int main()
{
srand((unsigned)time(0))
int ran
for (int i = 0
i < 2
i++)
{
ran = (rand() % 10) + 1
cout << ran
}
}
Correct Answer
(C) Any two number from 1 to 10
[#908] What will be the output of the following C++ code? #include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
#include <string>
using namespace std
int main ()
{
vector <string*> numbers
numbers.push_back ( new string ("one") )
numbers.push_back ( new string ("two") )
numbers.push_back ( new string ("three") )
vector <int> lengths ( numbers.size() )
transform (numbers.begin(), numbers.end(), lengths.begin(),
mem_fun(&string :: length))
for (int i = 0
i < 3
i++)
{
cout << lengths[i]
}
return 0
}
Correct Answer
(A) 335
[#909] 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
tp1 = make_tuple(6, 'a', "Hello")
int x
string y
tie(x,ignore,y) = tp1
cout<<"x: "<<x<<"
y: "<<y<<endl
return 0
}
Correct Answer
(A) x: 6 y: Hello
[#910] What will be the output of the following C++ code? #include<iostream>
using namespace std
class Print
{
public:
void operator()(int a){
cout<<a<<endl
}
}
int main()
{
Print print
print(5)
return 0
}
Correct Answer
(A) 5