adplus-dvertising
frame-decoration

Question

What would be the output of following code snippet?
{
     try 
     {
         int i, sum;
         sum = 10;
         for (i = -1 ;i < 3 ;++i) 
         {
             sum = (sum / i);
             Console.WriteLine(i);
         }
     }
     catch(ArithmeticException e) 
     {
         Console.WriteLine("0");
     }
     Console.ReadLine();
 }

a.

-1

b.

0

c.

-1 0

d.

-1 0 -1

Posted under C# programming

Answer: (c).-1 0

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What would be the output of following code snippet?