In C What is the output include using namespace std int mai

In C++, What is the output ?

#include <iostream>

using namespace std;

int main() {

int a[6] = {5, 9,3, 7, 5, 8};

for (int i = 1; i <=4; i++)

    a[i] = i;

for (i = 0; i < 6; i++)

    cout << a[i] << \" \";

cout << endl;

return 0;

}

Solution

Array index always starts from 0. So, for the first loop i.e.

for(i=1;i<=4; i++)

a[i]=i;

it will assign a[1]=,a[2]=2,a[3]=3,a[4]=4. and the complete array looks as follows

a[6]={5,1,2,3,4,8}.

In the next loop they print 512348 as the cout statement don\'t have spaces. so it does print like it.

In C++, What is the output ? #include <iostream> using namespace std; int main() { int a[6] = {5, 9,3, 7, 5, 8}; for (int i = 1; i <=4; i++) a[i] = i;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site