+ 1
Explain the error here in detail!!
4 Respuestas
+ 1
Thats the question! Why can't the reference variable hold arrays?
0
#include <iostream>
using namespace std;
int main()
{
int arr[] = {1, 2 ,3, 4, 5};
int *zarr = arr; // you can assign a array to int variable so use a pointer to refference the arr array....
for(int i = 0; i <= 4; i++)
{
arr[i] += arr[i];
}
for(int i = 0; i <= 4; i++) // i is not declared in your code here
cout<< zarr[i];
return 0;
}
0
Mr. Curious look at the following as you used & instead of * for pointer and i needed re-initializing in second loop
https://code.sololearn.com/cYVJtIr1oCqe/?ref=app
0
Mr. Curious There arr is a pointer type (it can hold continuous memory locations..) and if you write int &zarr then here zarr is just an Integer so how can it hold an array..? So not compatible types both so it is an error.