Pergunta

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

Foi útil?

Solução

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).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top