Learn C the Hard Way – big numbers


If you take a number that has an optional sign, you need to leave room for the negative numbers. If you don’t, all that room can be added up top instead, effectively doubling the size of the number-holder you can play with, as long as it’s positive. If all you’re concerned with is the size of the number, that’s cool. You’ve got a box that’s twice as long, but each unit in the box is double the size of the one before, so an unsigned long is really MASSIVE.

It came out as 0 on my output. I don’t know why. Um, maybe the computer itself couldn’t handle it? Compiler was happy, valgrind was happy, but it was outputting as 0. I’ll have a think.

Extra credit asks about why chars and ints can be treated just about the same. Well, it’s just ones and zeros, innit? So if the char and the int can be interchanged, then they get to be. If not, if one won’t fit into the other, just throw a wobbly in the compiler.