How to pass multi-dimensional array to function?

后端 未结 3 1997
猫巷女王i
猫巷女王i 2021-01-24 12:06

I am trying to pass a 2D array of variable size to a function to print it.but the code doesn\'t show the exact result of sum.

this is the code:

#include         


        
3条回答
  •  悲哀的现实
    2021-01-24 12:46

    You should pass the exact size of the second dimension of the array to the function, not COLL. change it to m (or n, whatever) It passes the number 5 to the function while the number should be 3 :) How ever, this is not the main reason that you're code is not working, just a suggestion. Initialize the variable sum. It will make your code work. e.g. sum = 0; If you don't initialize it, you won't get any compile errors, but it points to a location of memory and reads thing been there before (not a valid amount) and uses it as the initial amount of that for sum. So your array is being added to a non-valid amount, that's why your code doesn't work.

提交回复
热议问题