C Plus Plus Miscellaneous - Study Mode

[#901] What will be the output of the following C++ code? #include <iostream>
#include <utility>

using namespace std
int main ()
{
pair <int,int>p
p = make_pair(1,2)
cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")
"
return 0
}
Correct Answer

(A) Pair(first,second) = (1,2)

[#902] What will be the output of the following C++ code? #include <iostream>
#include <exception>
using namespace std
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception"
}
} myex
int main ()
{
try
{
throw myex
}
catch (exception& e)
{
cout << e.what() << endl
}
return 0
}
Correct Answer

(C) My exception

[#903] What is the correct syntax of declaring an array class?
Correct Answer

(B) array<type,size> arr

[#904] What will be the output of the following C++ code? #include <iostream>
using namespace std
class Base
{
public:
virtual void print() const = 0
}
class DerivedOne : virtual public Base
{
public:
void print() const
{
cout << "1"
}
}
class DerivedTwo : virtual public Base
{
public:
void print() const
{
cout << "2"
}
}
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
{
DerivedTwo::print()
}
}
int main()
{
Multiple both
DerivedOne one
DerivedTwo two
Base *array[ 3 ]
array[ 0 ] = &both
array[ 1 ] = &one
array[ 2 ] = &two
for ( int i = 0
i < 3
i++ )
array[ i ] -> print()
return 0
}
Correct Answer

(B) 212

[#905] What is the name of the myfile2 file after executing the following C++ code? #include <stdio.h>
int main ()
{
int result
char oldname[] = "myfile2.txt"
char newname[] = "newname.txt"
result = rename(oldname, newname )
if (result == 0)
puts ( "success" )
else
perror( "Error" )
return 0
}
Correct Answer

(C) newname