美文网首页技术文
C++中获取数组元素个数的方法

C++中获取数组元素个数的方法

作者: llnhhy | 来源:发表于2016-11-06 21:04 被阅读0次

假设有数组

int ia[3][5] = {
  {0, 1, 2, 3, 4},
  {5, 6, 7, 8, 9},
  {10, 11, 12, 13, 14}
};

如果我们想获取ia数组第一层维度的长度,可以使用

int num = sizeof(ia)/sizeof(ia[0])

如果想获取ia数组第二层维度的长度,可以使用

int num = sizeof(ia[0])/sizeof(ia[0][0])

以此类推

相关文章

网友评论

    本文标题:C++中获取数组元素个数的方法

    本文链接:https://www.haomeiwen.com/subject/sdenuttx.html