How do I find the length of an array?

前端 未结 27 2883
轮回少年
轮回少年 2020-11-21 23:10

Is there a way to find how many values an array has? Detecting whether or not I\'ve reached the end of an array would also work.

27条回答
  •  梦如初夏
    2020-11-21 23:10

    Avoid using the type together with sizeof, as sizeof(array)/sizeof(char), suddenly gets corrupt if you change the type of the array.

    In visual studio, you have the equivivalent if sizeof(array)/sizeof(*array). You can simply type _countof(array)

提交回复
热议问题