Can I check in C(++) if an array is all 0 (or false)?

后端 未结 8 587
执念已碎
执念已碎 2020-12-21 01:34

Can I check in C(++) if an array is all 0 (or false) without iterating/looping over every single value and without allocating a new array of the same size (to use memc

8条回答
  •  失恋的感觉
    2020-12-21 01:35

    If you know that this is going to be a requirement, you could build a data structure consisting of an array (possibly dynamic) and a count or currently non-zero cells. Obviously the setting of cells must be abstracted through, but that is natural in c++ with overloading, and you can use an opaque type in c.

提交回复
热议问题