C Plus Plus Miscellaneous - Study Mode

[#676] What will be the output of the following C++ code? #include <iostream>
using namespace std

void Sum(int a, int b, int & c)
{
a = b + c

b = a + c

c = a + b

}
int main()
{
int x = 2, y =3

Sum(x, y, y)

cout << x << " " << y

return 0

}
Correct Answer

(C) 2 15

[#677] What will be the output of the following C++ code? #include <iostream>
#include <vector>
using namespace std

int main ()
{
vector<int> myvector

int sum (0)

myvector.push_back (100)

myvector.push_back (200)

myvector.push_back (300)

while (!myvector.empty())
{
sum += myvector.back()

myvector.pop_back()

}
cout << sum << '
'

return 0

}
Correct Answer

(B) 600

[#678] Choose the correct formatted code.
Correct Answer

(B) cout << "Hai" << "Good morning" << endl
(F) int main() { cout << "5" }
(I) int a = 5

[#679] What will be the output of the following C++ code? #include <iostream>
using namespace std

double division(int a, int b)
{
if (b == 0)
{
throw "Division by zero condition!"

}
return (a / b)

}
int main ()
{
int x = 50

int y = 0

double z = 0

try
{
z = division(x, y)

cout << z << endl

}
catch (const char* msg)
{
cerr << msg << endl

}
return 0

}
Correct Answer

(C) Division by zero condition!

[#680] What will be the output of the following C++ code? #include <iostream>
using namespace std

template<class T = float, int i = 5> class A
{
public:
A()

int value

}

template<> class A<>
{
public: A()

}

template<> class A<double, 10>
{
public: A()

}

template<class T, int i> A<T, i>::A() : value(i)
{
cout << value

}
A<>::A()
{
cout << "default"

}
A<double, 10>::A()
{
cout << "10" << endl

}
int main()
{
A<int, 6> x

A<> y

A<double, 10> z

}
Correct Answer

(C) 6default10