Puzzle 19A Little Sum Thing

 #include <iostream>
 #include <numeric>
 #include <vector>
 
 int​ ​main​()
 {
  std::vector<​int​> v{-2, -3};
  std::cout << std::accumulate(v.cbegin(), v.cend(), v.size());
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program has implementation-defined behavior! But it outputs a large number, like this one for instance:

 18446744073709551613
images/hline.png

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.