这是本人遇到的一个面试题目,当时想了一个间接的方法,就是声明两个变量,然后两个变量的地址相减。以下方法更直接:
size_t a = reinterpret_cast<int>(((long*)(0)+1)) -reinterpret_cast<int>(((long*)(0)));
如果不使用reinterpret_cast进行转换,结果就是1.
这是本人遇到的一个面试题目,当时想了一个间接的方法,就是声明两个变量,然后两个变量的地址相减。以下方法更直接:
size_t a = reinterpret_cast<int>(((long*)(0)+1)) -reinterpret_cast<int>(((long*)(0)));