문제

an interview question on glassdoor is as follows. With my knowledge, it is hard to deduce anything out of it. What could be an appropriate question?

A macro that computes a size_t number. Putting in a loop, it casts -1 to a size_t number, making the loop impossible to start.

as suggested by Michael Aaron Safyan, following might be the case

operates in the reverse:

for (size_t i = 0; i > ((size_t) -1); i--) {}

For explanation see the answer

도움이 되었습니까?

해결책

The issue is that size_t is unsigned, so casting -1 to it will produce the maximum-valued size_t. One would fix this case by using a signed type (such as int or ssize_t).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top