0

Beyond limit ?

i know the longest data type is unsigned long long, but what happen when we assign number beyond the limit? shouldn't it output error? but it output strange number ? where is that number come from? see my code below : https://code.sololearn.com/cNyRlDBZS9ax/?ref=app

13th May 2017, 8:44 AM
Setiawan Next
Setiawan Next - avatar
9 Answers
+ 2
It would have different numbers for different compiler, especially compiler that run on different machine 32/64 bits.
13th May 2017, 9:24 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 1
it doesn't error because it isn't technically wrong. youve tried to assign a number that is too big and the program just returns what the pointer is pointing to. the same way changing a double into an int just removes everything after the decimal without an error
13th May 2017, 9:03 AM
Daemo
Daemo - avatar
+ 1
thanks @Daemo, so it was not random number? does it output different number in different compiler? i mean the "too big number".
13th May 2017, 9:15 AM
Setiawan Next
Setiawan Next - avatar
+ 1
You have reached the edge of the Universe.
13th May 2017, 9:16 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 1
@setiawan I have not compared between different compilers but I'm sure someone must have done this before
13th May 2017, 9:20 AM
Daemo
Daemo - avatar
+ 1
@Calvin Do i just get the world record title as "the first human who reach the edge of universe and still don't understand where the strange number come from" and then Dr. Strange will answer : " it come the part of universe which exist before the time"
13th May 2017, 9:23 AM
Setiawan Next
Setiawan Next - avatar
+ 1
@Calvin oh, i see. thanks, i'll try it tonight.
13th May 2017, 9:27 AM
Setiawan Next
Setiawan Next - avatar
+ 1
@Setiawan, No, it's not a world record but an universe record. From Albert Einstein theory, General Theory of Relativity, it said the Universe is like a Computer underlines with numbers and information. I think the God, must be the universe top coder.
13th May 2017, 9:29 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 1
Depends on your compiler. If your compiler does nothing about it or doesnt give you any errors when you try to compile, the variable will just be set to the largest negative value, or 0 if the variable is unsigned. It works like a speedometer.
13th May 2017, 12:44 PM
aklex
aklex - avatar