计算数组的大小 [英] Calculating the size of an array

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

问题描述

嗨!

我读过,在C ++中没有预定义的方法来计算数组的大小。但是,它应该与

Hi!
I''ve read, that in C++ there''s no predefined method, to calculate the size of an array. However, it''s supposed to work with

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

推荐答案


我不想将这种信息作为参数传递给每个函数,需要手动调整数组的大小。
I''d hate to have to pass on that kind of information as an argument to every function, that needs the size of the array, manually.



对不起。传递信息。曾经看过像stncpy这样的C stdlib函数吗?猜猜他们为什么要求你手动告诉他们数组的大小。

Sorry. Pass the information. Ever see C stdlib functions like strncpy? Guess why they ask you to manually tell them the size of the array.


你可以在你的数组中使用一些终止元素,然后你的长度函数计算直到终止元素的元素数量。 C字符串是以这种方式以空值终止的字符数组。
You could use some terminating element in your array, then your length function count the number of elements until the terminating element. C strings are character arrays that are null terminated in this manner.



对不起。传递信息。曾经看过像stncpy这样的C stdlib函数吗?猜猜他们为什么要求你手动告诉他们阵列的大小。
Sorry. Pass the information. Ever see C stdlib functions like strncpy? Guess why they ask you to manually tell them the size of the array.



Grrr ...为什么C ++不能像那样更像Java ... :-(

Grrr... Why can''t C++ be a bit more like Java in that way... :-(


你可以在数组中使用一些终止元素,然后你的长度函数计算元素的数量,直到终止元素.C字符串是以这种方式终止的字符数组。
You could use some terminating element in your array, then your length function count the number of elements until the terminating element. C strings are character arrays that are null terminated in this manner.



这有点困难,如果它是一个整数数组,因为这意味着,我不能使用某些特定的数字。

但是这样的事情:

That''s a bit difficult, if it''s an array of integers, because that would mean, that I can''t use some specific numbers.
But how about something like this:

展开 | 选择 < span class =codeDivider> | Wrap | 行号


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

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