Does sizeof return the number of bytes or the number of octets of a type in C?

后端 未结 4 561
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 12:09

Simply put in C and variants (unlike that wuss java with its virtual machine) the size of primitive types on different targets can vary greatly, and there is really no guarantee

4条回答
  •  别那么骄傲
    2021-02-02 13:01

    sizeof always returns size as the number of bytes. But according to wikipedia:

    In the programming languages C and C++, the unary operator sizeof is used to calculate the size of any datatype, measured in the number of bytes required to represent the type. A byte in this context is the same as an unsigned char, and may be larger than 8 bits, although that is uncommon.

提交回复
热议问题