+ 1

Explain the error here in detail!!

https://code.sololearn.com/ct402DLSvGYx/?ref=app

24th Sep 2020, 6:42 PM
Mr. Curious
Mr. Curious - avatar
4 Respuestas
+ 1
Thats the question! Why can't the reference variable hold arrays?
24th Sep 2020, 7:15 PM
Mr. Curious
Mr. Curious - avatar
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; }
24th Sep 2020, 7:11 PM
Jayakrishna 🇮🇳
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
24th Sep 2020, 7:13 PM
BroFar
BroFar - avatar
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.
24th Sep 2020, 7:38 PM
Jayakrishna 🇮🇳