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

前端 未结 11 1840
陌清茗
陌清茗 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 15:09

    In the code above, function f() has no way of knowing how many elements were in your original array. It's a feature of the language and there's no way around it. You'll have to pass the length.

提交回复
热议问题