Can a two-dimensional array in C be initialized without explicit size?

后端 未结 5 2064
一整个雨季
一整个雨季 2021-01-11 13:27

I have a question regarding two-dimensional arrays in C. I know now (from direct compiler experience) that I can\'t initialize such an array analogously to one-dimensional a

5条回答
  •  心在旅途
    2021-01-11 14:03

    2D arrays in C are stored in contiguous memory locations. So if you do not provide the number of rows or the number of columns, how will the compiler know how many rows and column there are?

    For a row major matrix, rows contents are at contiguous memory positions. So you need to specify at least the number of columns. Similarly for a column major matrix, you need to specify at least the number of rows. Whether it is row major or column major is defined by architecture. It seems that what you have is a row major architecture.

提交回复
热议问题