How does sizeof know the size of the operand array?

前端 未结 12 1261
臣服心动
臣服心动 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 13:48

    Sizeof is a compile time operator; it has as much information as the compiler does. (And obviously the compiler does know the size of the array).

    This is why if you call sizeof on a pointer you get the width of the pointer, not the size of the array to which that pointer points.

提交回复
热议问题