-
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;
}
-
- 70
- 40
- 30
- 184
- 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.