C Plus Plus Miscellaneous - Study Mode

[#581] Which is a constant defined in <cstdlib> header file?
Correct Answer

(A) RAND_MAX

[#582] Which exception is thrown by dynamic_cast?
Correct Answer

(A) bad_cast

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

int main ()
{
vector<int> myvector (3)

for (unsigned i = 0

i < myvector.size()

i++)
myvector.at(i) = i

for (unsigned i = 0

i < myvector.size()

i++)
cout << ' ' << myvector.at(i)

return 0

}
Correct Answer

(B) 0 1 2

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

int main ()
{
int i, n

int * p

i = 2

p= new (nothrow) int[i]

if (p == 0)
cout << "Error: memory could not be allocated"

else
{
for (n=0

n<i

n++)
{
p[n] = 5

}
for (n = 0

n < i

n++)
cout << p[n]

delete[] p

}
return 0

}
Correct Answer

(B) 55

[#585] What is the correct syntax of defining function template/template functions?
Correct Answer

(A) template <class T> void(T a){cout<<a }