Pass a two dimensional array to a function of constant parameter

前端 未结 2 1856
陌清茗
陌清茗 2020-11-27 07:33

I learned from C Primer Plus that if you want to protect an array from being accidentally modified by a function, you should add const modifier before

2条回答
  •  Happy的楠姐
    2020-11-27 08:22

    You can type cast the array while calling the function. It will not automatically convert non-const into const. You can use this.

    Sum2D( (const int (*)[])array, ROWS );
    

提交回复
热议问题