How does sizeof know the size of the operand array?

前端 未结 12 1225
臣服心动
臣服心动 2020-12-03 13:16

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 does

12条回答
  •  既然无缘
    2020-12-03 14:04

    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.

提交回复
热议问题