Getting the size of the data of a Pointer

前端 未结 5 665
借酒劲吻你
借酒劲吻你 2020-12-10 06:52

I tried the following code in order to see how to get size of the data of a pointer:

 #include 
 #include 
 #include 

        
5条回答
  •  一向
    一向 (楼主)
    2020-12-10 07:55

    sizeof only knows the full size of the array if that's statically known at compile time. For a pointer, it will return the size of the memory address, i.e. 4 on 32-bit, 8 on 64-bit.

    When you use pointers, it's up to you to know and keep track of the size of the data it points to. The language implementation won't do it for you like it would for arrays.

提交回复
热议问题