C: finding the number of elements in an array[]

前端 未结 11 1863
陌清茗
陌清茗 2020-12-16 14:31

In C: How do you find the number of elements in an array of structs, after sending it to a function?

int main(void) {
  myStruct array[] = { struct1, struct2         


        
11条回答
  •  忘掉有多难
    2020-12-16 14:56

    You can't tell number of elements in an array in C consistently. Specially if you pass the array around through pointers.

    Usually, if you must use array size in a function, pass it as a parameter to it.

提交回复
热议问题