What is the output of the following C++ program?
#include <iostream>
class StockCounter {
unsigned count_ = 0;
public:
void add(unsigned n) { count_ += n; }
bool remove(unsigned n) {
if (n > count_) return false;
count_ -= n;
return true;
}
unsigned count() const { return count_; }
};
int main() {
StockCounter s;
s.add(5);
bool a = s.remove(3), b = s.remove(4), c = s.remove(2);
std::cout << a << b << c << ' ' << s.count() << '\n';
return 0;
}
Removing 4 from 2 is refused, so the unsigned counter never wraps around to a huge value. The final count is 0.