How does sizeof know the size of the operand array?

前端 未结 12 1258
臣服心动
臣服心动 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:06

    If you're using sizeof on a local variable, it knows how many elements you declared. If you're using sizeof on a function parameter, it doesn't know; it treats the parameter as a pointer to the array and sizeof gives the size of a pointer.

提交回复
热议问题