Why does 2 dimension array passing to function requires its size?

前端 未结 3 564
说谎
说谎 2021-01-20 20:39

Inspired this quiestion .

Why does -

void display(int p[][SIZE]) // allowed

and

void display(int p[][]) // not a         


        
3条回答
  •  花落未央
    2021-01-20 21:23

    That's because caculations in pointers requires that. When p points to 2 dimentional array that's size is SIZE this operation p+=3 is calculated this way:

    if the value of p is a constant equal ADRESS p receive this value ADRESS + 3*SIZE.

    That's because arithmitic in pointers is different from arithmitic in real numbers. This calculation can't be done without knowing the size of the array.

提交回复
热议问题