Thursday 2 December 2010

What will be the output of the following segment of C++ code?

int A[5] = {1 , 2, 3, 4};
int i;
for (i=0; i<5; i++)
{
A[i] = 2*A[i];
cout << A[i] << "  ";
}
2 4 6 8 0
Loops will run 5 times as its starting from zero. It will multiply the value of each item in array as
last time is not initialized so it will multiply it with zero to give zero as output

No comments:

Post a Comment