Sail E0 Webinar
Question


What will be the output of the this program?


1.
#include
2.
using namespace std;
3.
int main ()
4.
{
5.
int array[] = {0, 2, 4, 6, 7, 5, 3};
6.
int n, result = 0;
7.
for (n = 0; n < 8; n++) {
8.
result += array[n];
9.
}
10.
cout
Options:
A .  25
B .  26
C .  27
D .  None of the mentioned
Answer: Option D

We are adding all the elements in the array and printing it. Total elements in the array is 7, but 

our for loop will go beyond 7 and add a garbage value.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers