问题描述
这可能是一个愚蠢的问题,但如何sizeof操作符知道数组操作数的大小,当你在数组中元素的含量不及格。我知道这不返回数组,但以字节为单位的大小,总的元素,但要获得它仍然必须知道何时数组结束。只是好奇,这是如何工作的。
This may be a stupid question but how does the sizeof operator know the size of an array operand when you don't pass in the amount of elements in the array. I know it doesn't return the total elements in the array but the size in bytes, but to get that it still has to know when the array ends. Just curious as to how this works.
推荐答案
的sizeof
是在编译时PTED间$ P $,并且编译器知道数组是怎么声明(因此多少空间它占用)。调用的sizeof
一个动态分配的阵列上可能不会做你想做的,因为(你提到)未指定数组的终点。
sizeof
is interpreted at compile time, and the compiler knows how the array was declared (and thus how much space it takes up). Calling sizeof
on a dynamically-allocated array will likely not do what you want, because (as you mention) the end point of the array is not specified.
这篇关于如何知道的sizeof操作数数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!