← Quiz: STL Algorithms: all 10 questions
Quiz: STL Algorithms · Question 10 of 10
Why is accumulate(v.begin(), v.end(), 0) risky for a vector of large long long values?
Why is accumulate(v.begin(), v.end(), 0) risky for a vector of large long long values?
- A.accumulate cannot add long long
- B.The type of the starting value 0 is int, so the running sum is kept in an int and can overflow
- C.It skips the last element
- D.It sorts the vector first
Answer & explanation
Correct answer: The type of the starting value 0 is int, so the running sum is kept in an int and can overflow
Write 0LL as the start value so the sum is computed in long long.
Can you get the rest right without peeking?
Take the timed Quiz: STL Algorithms quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →