C Plus Plus Miscellaneous - Study Mode
[#601] What will be the output of the following C++ code? #include <iostream>
#include <exception>
#include <cstdlib>
using namespace std
void myterminate ()
{
cerr << "terminate handler called"
abort()
}
int main (void)
{
set_terminate (myterminate)
throw 0
return 0
}
Correct Answer
(C) both terminate handler & Aborted
[#602] What will be the output of the following C++ code? #include int main ()
{
FILE * p
long size
p = fopen ("test.txt", "rb")
if (p == NULL)
perror ("Error opening file")
else
{
fseek (p, 0, SEEK_END)
size = ftell (p)
fclose (p)
printf (" %ld
", size)
}
return 0
}
Correct Answer
(D) Depends upon the file
[#603] What will be the output of the following C++ code? #include <iostream>
#include <vector>
using namespace std
int main()
{
vector<int> v
for (int i = 1
i <= 5
i++)
v.push_back(i)
vector<int> :: iterator i
i = v.begin()
*i = 3
for (i = v.begin()
i != v.end()
++i)
cout << *i << " "
cout<<endl
return 0
}
Correct Answer
(B) 3 2 3 4 5
[#604] What will be the output of the following C++ code? #include <iostream>
using namespace std
class MyException
{
public:
MyException(int value) : mValue(value)
{
}
int mValue
}
class MyDerivedException : public MyException
{
public:
MyDerivedException(int value, int anotherValue) : MyException(value), mAnotherValue(anotherValue)
{
}
int mValue
int mAnotherValue
}
void doSomething()
{
throw MyDerivedException(10,20)
}
int main()
{
try
{
doSomething()
}
catch (MyDerivedException &exception)
{
cout << "
Caught Derived Class Exception
"
}
catch (MyException &exception)
{
cout << "
Caught Base Class Exception
"
}
return 0
}
Correct Answer
(B) Caught Derived Class Exception
[#605] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
using namespace std
int main ()
{
int myints[] = { 10, 20, 30 ,40 }
int * p
p = find (myints, myints + 4, 30)
--p
cout << *p << '
'
return 0
}
Correct Answer
(B) 20