Here says:

Why did we allocate an array of size 12 for our representation of that int as a string? No worries if the reason’s non-obvious, but give some though as to how wide the most positive (or most negative!) int might be.

What does that means?

1 Answer 1


The question is hinting at you to think about why the array is initialized with a size of 12.

An integer, given how it is represented in computer memory on 32 bit systems (such as the appliance), has a finite value. Affording for the '/n' character at the end of a string results in a maximum width of 12 characters for the integer -(231) and 11 characters for 231-1.

  • Aren't -(2^31) -and 2^31 - 1, respectively, 2147483648(1 and 2147483647, both 10 digits?
    – RexYuan
    Nov 29, 2014 at 6:46
  • And isn't the size of char 1 byte while that of int is 4? So 12 chars make 3 ints? I'm really confused
    – RexYuan
    Nov 29, 2014 at 6:48
  • No, -2147483648 when written as a string is 11 characters, count them in this sentence. The size of an integer in computer memory has nothing to do with the string representation of the integer.
    – bobbitworm
    Nov 30, 2014 at 11:40
  • and 12th char is \0
    – taichouvik
    Jun 29, 2016 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .