简体   繁体   English

memory中数组的结束地址如何获取? C编程

[英]How do you get the ending address of an array in memory? C programming

If I have an address in memory for the start of an integer array, how do I figure out the end address of the array?如果我在 memory 中有一个地址作为 integer 数组的开始,我如何计算出数组的结束地址?

For example, if an array started at 0xFF000000 how would you return the address where the array ends?例如,如果一个数组从 0xFF000000 开始,您将如何返回数组结束的地址?

given an address for an array of integers, you need to know how many are in the array since an integer can be zero.给定一个整数数组的地址,您需要知道数组中有多少个整数,因为 integer 可以为零。 in other words without a delimiter indicated the end of the array, there is no way to know how many values were ACTUALLY stored in the array.换句话说,如果没有分隔符表示数组的结尾,就无法知道数组中实际存储了多少个值。

a basic heap array should at least have a second variable storing the number of elements.一个基本的堆数组应该至少有第二个变量存储元素的数量。 how else was it allocated right?否则它是如何分配的?

int nElements = 10; int *pInts = (int*)malloc(nElements * sizeof(int)); int *pEndOfArrayAddress = pInts + (nElements-1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM