Answers/Solutions to Exercises in Chapter 3, Exercise 2

E2: Assume that the value of an int variable i is not zero. Do you think it is possible that i += 3*i will set the value of i to zero? If so, under what circumstances?

A2: Yes, it is possible. Of course, the circumstances depend on the platform. On a typical 32-bit architecture under Windows, if i=1073741824, then i+3*i=0. In general, it will happen when i=(MAX_INT+1)/4, for then i+3*i=4*i=MAX_INT+1=0.

Back to Answers/Solutions Index                          Back to Answers/Solutions for Chapter 3 Index