arrays - 如何确定数组在c中的维数
问题描述
所以我想创建一些以数组作为输入的函数,但我不知道数组会有多少维。
c中有没有办法确定数组有多少维?(理想情况下作为一个函数)
解决方案
So this is actually a fairly difficult problem in C. Usually this is solved using one of three ways:
- Have a special terminating value, like
'\0'
for strings - Pass the dimensions of the array as a parameter to whatever function you're using
- Keep the pointer of the array and its dimension in a
struct
together
If I remember correctly, there's a way to figure out the size of an allocated array using *nix systems, but I definitely would not recommend doing this. Just keep track of your allocated memory.
推荐阅读
- c++ - 从多个线程访问类对象
- php - 如何让sqlite查询在mysql上工作?
- xml - 我可以创建一个增加页数的循环吗?
- amazon-web-services - 如何获取通过 UI 部署的 lambda 函数的 SAM 模板?
- conan - 使用 conans.tools.download() 时如何配置柯南以接受公司 CA?
- c# - 如何区分这两个行索引
- python - 如何确定一个点是否位于 3D 空间中的多边形内?
- anaconda - Anaconda 提示不显示(基本)环境,而是显示路径
- python - H2O - 在网格搜索中使用 LASSO 进行特征选择
- form-recognizer - 使用表单识别器进行监督学习