Home » C++ Programming » Arrays » Question
  1. What will be the output of the this program?
    #include 
    using namespace std;
    int main ()
    {
    int arr[] = {10, 12, 40, 16, 70, 15, 30};
    int k, res = 0;
    for (k = 0; k < 5; k++) {
    res += arr[k];
    }
    cout << res;
    return 0;
    }
    1. 70
    2. 40
    3. 30
    4. 184
    5. 148
Correct Option: E

We are adding all the elements in the array and printing it. Total elements in the array is 5, but our for loop will go beyond 5 and add a garbage value.



Your comments will be displayed only after manual approval.