如何从指针变量计算数组的大小? [英] How to calculate size of array from pointer variable?

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

问题描述

我有数组的指针(内存中的数组).我可以从它的指针计算数组的大小吗?我实际上不知道内存中的数组在哪里.我只得到指针地址(假设 9001)使用该地址我必须计算数组大小.

i have pointer of array(array which is in memory). Can i calculate the size of array from its pointer ? i dont know actually where is the array in memory. i only getting pointer adress(suppose 9001) using that adress i have to calculate array size.

谢谢.

推荐答案

不,您不能计算数组的大小.C中的对象不携带类型信息,所以必须提前安排知道数组的大小.像这样:

No, you cannot calculate the size of the array. Objects in C do not carry type information, so you must arrange to know the size of the array ahead of time. Something like this:

void my_function(int array[], int size);

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

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