Value changing when I pass array into function

There is a huge mess there, you need to get used to pointers!

Ok so your function gets g and p which are int *. What you give them is &g and &p, where g and p are also int *. So you pass to your function type int **.

Also g[i+3] is *(g+i+3) so lets see what *g[i+3] is.

g is the address of the address of the first element of your array. g[i+3] is i+3 spots next to the address of the address blah blah blah… so *g[i+3] is the content of that!

It’s something you probably have no idea about!

Try to pass g and p instead of &g and &p and remove all the * from your function.

Leave a Comment