Question OOP-EXC-0046
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
int safeDiv(int a, int b) {
if (b == 0) throw 0;
return a / b;
}
int main() {
int s = 0;
int d[] = {2, 0, 5};
for (int x : d) {
try { s += safeDiv(10, x); }
catch (int) { s += 100; }
}
cout << s;
}
- A.
7
- B.
107
- C.
100
- D.
5
Sign up free to see the answer and a step-by-step explanation.