如何知道整数数组的大小? [英] how to know size of integer array?

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

问题描述

困扰我这么久,我们可以找到字符串数组(char数组)的大小但是找到整数数组大小的方法是什么?我已经尝试过使用while循环,直到它找到''\0'''null字符,只要遇到整数0就停止,这不是我想要的......有人请帮帮我

Been bothering me so long, we can find the size of string array (array of char) but what is the way to find the size for integer array? I''ve tried using while loop until it find ''\0'' null character, it''s stop whenever integer 0 is encountered, which is not what I want .. anyone please help me

推荐答案

使用sizeof运算符找到整数数组的大小与查找char数组大小或任何数组大小的方式相同

所以对于任何类型T

You find the size of an integer array in the same way that you find the size of a char array or the size of any array, using the sizeof operator

So for any type T

展开 | 选择 | Wrap | 行号


谢谢你的回答,但我是什么需要找到的是arr的大小ay(整数数组的长度)也许我说它不够清楚,抱歉


我用过sizeof [n]但它每次都返回相同的值(4)我不知道为什么

其中n是整数数组,我将整数数分配给它


请帮忙
thank you for your answer, but what I need to find is the size of array (length of array of integer) maybe I said it not clear enough, sorry

I''ve used sizeof [n] but it returns me same value each time (4) I don''t know why
where n is array of integer, which I assign numbers of integer into it

please help


我在之前的帖子中给了你正确的解决方案。如果没有指定[n]是什么,你刚发布的内容是没有意义的。


如果你说的是真的


int array [5];


sizeof(array)== 4

然后你的编译器就有一个bug。


我建议您发布您正在使用的实际代码,因为它更可能存在不同的错误,例如它是真的和数组还是它是指向您的int的指针为整数数组分配内存。
I have given you the correct solution in my previous post. what you have just posted does not make sense without you specifying what [n] is.

If what you say is true for

int array[5];

sizeof(array) == 4

then there is a bug in your compiler.

I suggest however that you post the actual code you are using as it is more likely that there is a different error, for instance is it really and array or is it a pointer to an int to which you are assigning memory for an array of integers.


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

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