Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void PrintSequence(int StopNum)
4.
{
5.
int Num;
6.
Num = 1;
7.
while (true) {
8.
if (Num >= StopNum)
9.
throw Num;
10.
cout
Options:
A .  compile time error
B .  prints first 19 numbers
C .  prints first 19 numbers and throws exception at 20
D .  none of the mentioned
Answer: Option C

In this program, we are printing upto 19 numbers and when executing the 20, we are raising 

a exception.
Output:
$ g++ excep1.cpp
$ a.out
12345678910111213141516171819Caught an exception with value: 20



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers