CJCoding With Joseph
← Back to Question List
C++ Code Walkthrough #46

Stepping Through an Array by Twos

easyLoops

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3 
4int main() {
5 int arr[] = {2, 4, 6, 8, 10};
6 int sum = 0;
7 for (int i = 0; i < 5; i += 2) {
8 sum += arr[i];
9 }
10 cout << sum << endl;
11 return 0;
12}

🎯 Your Answer