Question from the Language C - Fundamentals test

Find the sum of all even numbers in an array in C

Easy

What is the value of the result variable after executing the following C code?

#include <stdio.h>

int main() {
  int array[] = {1, 2, 3, 4, 5};
  int length = sizeof(array) / sizeof(array[0]);
  int result = 0;

  for (int i = 0; i < length; i++) {
    if (array[i] % 2 == 0) {
      result += array[i];
    }
  }

  printf("Result: %d\n", result);
  return 0;
}
Author: Vincent CotroStatus: PublishedQuestion passed 263 times
Edit
3
Community EvaluationsNo one has reviewed this question yet, be the first!