Skip to main content
1 of 2
chux
  • 33.7k
  • 2
  • 38
  • 92

Overflow

i*i can overflow (given a pause every 24, it would take a lot of enters).

To prevent overflow, use a wider type for the multiplicaiton.

#include <inttypes.h>

// printf("%10d%10d\n", i, i*i);
printf("%10d %10lld\n", i, 1LL*i*i);
// or better
printf("%10d %10jd\n", i, (intmax_t)i*i);
chux
  • 33.7k
  • 2
  • 38
  • 92