遍历 C 数组 [英] Iterate through a C array

查看:25
本文介绍了遍历 C 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序中的某处创建了一个结构数组.

I have an array of structs that I created somewhere in my program.

稍后,我想遍历它,但我没有数组的大小.

Later, I want to iterate through that, but I don't have the size of the array.

如何遍历元素?还是我需要将尺寸存储在某个地方?

How can I iterate through the elements? Or do I need to store the size somewhere?

推荐答案

您可以将大小存储在某处,或者您可以拥有一个带有特殊值集的结构体用作哨兵,就像 \0 表示字符串结束.

You can store the size somewhere, or you can have a struct with a special value set that you use as a sentinel, the same way that \0 indicates the end of a string.

这篇关于遍历 C 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆