Question 2
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <iterator>
int main() {
int a[6] = {4, 8, 15};
int sum = 0;
for (int x : a) sum += x;
std::cout << sum << ' ' << std::size(a) << ' ' << a[5] << '\n';
return 0;
}
- A 27 6 0 Correct
- B 27 3 0
- C 27 6 15
- D Garbage
Correct Answer: Option A
The array has 6 elements; the three not listed are 0, so the sum is 4 + 8 + 15 = 27.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!