Computer Science Canada Returning 2D Arrays from a function |
Author: | a22asin [ Tue Sep 30, 2014 11:56 am ] | ||
Post subject: | Returning 2D Arrays from a function | ||
Hi, im trying to pass a 2d array to a function, then have the function modify the 2d array and return it back to the main. But im having trouble doing so. i Tried calling by reference so that i dont need to return, but with no luck. This is what i got:
|
Author: | Insectoid [ Tue Sep 30, 2014 1:17 pm ] |
Post subject: | RE:Returning 2D Arrays from a function |
Because an array is basically a pointer, it passes by reference automatically. What you have done here is pass a reference to that pointer instead of the pointer itself. Is like a pointer to a pointer. And since it's a 2d array, it's like a pointer to a pointer to a pointer! Removing that ampersand should fix it, but if not, then using int **c as your first argument should work as well, though some people might not like that. |
Author: | a22asin [ Tue Sep 30, 2014 1:40 pm ] |
Post subject: | RE:Returning 2D Arrays from a function |
ok, well i havent learned pointers yet so thats why im not sure how to use em. |