Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = -1;
6.
char *ptr;
7.
ptr = new char[256];
8.
try
9.
{
10.
if (x < 0)
11.
{
12.
throw x;
13.
}
14.
if (ptr == NULL)
15.
{
16.
throw " ptr is NULL ";
17.
}
18.
}
19.
catch (...)
20.
{
21.
cout
Options:
A .  -1
B .  ptr is NULL
C .  Exception occured: exiting
D .  none of the mentioned
Answer: Option C

catch(…) is used to catch all types of exceptions arising in the program.
Output:
$ g++ etea.cpp
$ a.out
Exception occured: exiting



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers