Please find the errors of the following code
a)
int x[5];
int k = 10;
for (k = 0; k <= 5; k++)
{
x[k] = k -1;
}
b)
int x[5];
for (k = 1; k <= 5; k++)
{
cout << x[k-1] << endl;
}
c)
int x[5]={1,2,3,4,5}, y[5];
y = x;
for (k = 0; k < 5; k++)
{
cout << y[k] << endl;
}
d)
int size;
cin >> size;
int myArr[size];
a)
int x[5];
int k = 10;
for (k = 0; k <5; k++) //here remove = . Otherwise the loop iterates 6 times.
{
x[k] = k -1;
}
b)
int x[5];
for (int k = 1; k <= 5; k++) //k is not declared
{
cout << x[k-1] << endl;
}
c)
int x[5]={1,2,3,4,5}, y[5];
y = x; //the error is array can not be copied
for (k = 0; k < 5; k++)
{
cout << y[k] << endl;
}
d)
There are no compiling errors.
Get Answers For Free
Most questions answered within 1 hours.