How can you find the size of a datatype without creating a variable or pointer, or using sizeof of the datatype?

后端 未结 5 397
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 09:37

The question shown below is an interview question:

Q) You are given/have a datatype, say X in C.

The requirement is to get the size of the datatype, without decl

5条回答
  •  清酒与你
    2021-02-04 10:11

    define sizeof_type( type ) (size_t)((type*)1000 + 1 )-(size_t)((type*)1000)

    The original is from this discussion. http://www.linuxquestions.org/questions/programming-9/how-to-know-the-size-of-the-variable-without-using-sizeof-469920/

提交回复
热议问题