Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
glassdoor的面试题如下。以我的知识,很难从中推断出任何东西。什么可能是一个合适的问题?
计算 size_t 数的宏。放入一个循环,它将 -1 转换为 size_t 数字,使循环无法启动。
正如 Michael Aaron Safyan 所建议的那样,以下情况可能是这样的
反向操作:
for (size_t i = 0; i > ((size_t) -1); i--) {}
解释见答案
问题在于它size_t是无符号的,因此将 -1 转换为它会产生最大值size_t。可以通过使用有符号类型(例如intor ssize_t)来解决这种情况。
size_t
int
ssize_t