+ 2

Changing Array using Pointer

I'm trying to change the values of an array using a pointer in a function but when I call the function an error occurs. Can anyone find the solution? This is the code I wrote in C++ language: #include<iostream> using namespace std; int lut[240] ={240 values} ; void chng(int *arr[], int c) { int j; for(j=0;j<=239;j++) {arr=&lut[j]; } for(j=0;j<=239;j++) {*arr[j] =*arr[j] +c;}} int main() { int i; chng(&lut, 25) ; --->error for(i=0;i<=239;i++) {cout<<lut[i] <<" ";} return 0;}

17th Sep 2017, 6:39 AM
Pouriya Boostani
Pouriya Boostani - avatar
1 Antwort
+ 3
don't call array lut by reference while calling the function . Call it like :- chng(lut,25) I hope it will work correctly then.
17th Sep 2017, 7:15 AM
RZK 022
RZK 022 - avatar