Multiple problems with question #144
Question 144 has several problems.
The correct answer depends on implementation details and the interpretation of the code can result in the correct answer in both branches depending on what those implementation details are. I recommend to refine the question so that it does not rely on implementation details since the question is intended to test the result when a negative is applied to a literal value rather than the implementation details of a long int.
I agree that this is a bit unfortunate. Do you have any ideas for improvement?
Would it be better if we did something like this? (I don't like to have questions with assumptions, but we kind of have that already in this one.)
int N[] = {0,0,0};
// Assume:
// std::numeric_limits<long int>::digits==63
// std::numeric_limits<int>::digits==31
// std::numeric_limits<unsigned int>::digits==32
for (long int i = -0xffffffff; i ; --i)
{
N[i] = 1;
}
std::cout << N[0] <<N [1] << N[2];
The question is seven years old, but I'll also ping the author and see if they have any input or ideas.
Completely forgot about this one. I never heard back from the author either. I suggest retracting this question.
This question has now been retracted.