How do I change long to unsigned long
both when assigning the value and inside the printf()?
long universe_of_defects = 1L * 1024L * 1024L * 1024L
printf(“The entire universe has %ld bugs.\n”, universe_of_defects);
is changing to this enough?:
unsigned long universe_of_defects = 1L * 1024L * 1024L * 1024L
printf(“The entire universe has %lu bugs.\n”, universe_of_defects);
unsigned long universe_of_defects = 1UL * 1024UL * 1024UL * 1024UL
Then you got the printf right.
Really weird how I missed this point in the extra credit of this exercise.
I went back to see what point was it, because I couldn’t remember doing it.
And check this out, I don’t know the exact answer to the other half of the point:
and try to find the number that makes it too big.
Replaced the first one with a 9 and I added a 9 in front of every int and the result was bigger than 4,294,967,295, but the compiler didn’t complain. It was
The entire universe has 6613628092416 bugs.
Then I added lots of 9999999999999999999999999 to each int and it finally complained, but I want to find out the first number that is out of the range in this case.
How did you do that, @meeee?
L.E. Oh, man, wait!
I read carefully this time:
Long unsigned integer type. Capable of containing at least the [0, 4,294,967,295] range
L.E.2: Nope, this is the max limit on my system. I don’t get it.
L.E.3 : I get it now! Each unsigned long has to be greater than the max allowed for the compiler to start screaming, not the result of the operation!
L.E.4 : Nope. Doesn’t scream at all.
I’ve encountered 2 problems.
one is to find the max size of each unsigned long. as u say It’s bigger than the formal number.
second was when a multiply of two numbers resulted in a number too big it also showed a warning. marking the ‘*’ mark as the problem. It still compiles though.
Though it doesn’t necessary mark the biggest numbers…
I set one of the unsigned long to 4,294,967,295 and now the value of “the entire universe”
is a negative number, having a “-” at the beginning of the number. That’s when using %lb at the printf(). After changing %lb to %lu the number is different and positive.
to tell the truth, these numbers are too big for me to start and trying to figure out what’s really going on here.
why are you using “UL” at the end of the number? I didn’t notice any technical difference between “L” and “UL”.
what is L.E?
Thank you for your replies
They make me learn better
UL is a combination of the 2 suffixes: U and L
If you use L, you make the integer a long instead of an int.
U makes it unsigned. So if you combine them you get UL, unsigned long.
L.E. - later edit