cppquiz icon indicating copy to clipboard operation
cppquiz copied to clipboard

Multiple problems with question #144

Open Walkerdine opened this issue 3 years ago • 1 comments

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.

Walkerdine avatar May 12 '22 05:05 Walkerdine

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.

knatten avatar May 29 '22 11:05 knatten

Completely forgot about this one. I never heard back from the author either. I suggest retracting this question.

knatten avatar Mar 06 '23 19:03 knatten

This question has now been retracted.

knatten avatar Dec 23 '23 10:12 knatten