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.
Share
sizeofis interpreted at compile time, and the compiler knows how the array was declared (and thus how much space it takes up). Callingsizeofon a dynamically-allocated array will likely not do what you want, because (as you mention) the end point of the array is not specified.