+ 8
If in Java price of variabile more then renge of Data type what is the output???
When we put larger value on a datatype the how about the remain value ? for example:
14 Respostas
+ 2
You will get overflow value..
For example if Integer range is
-2147483648 to 2147483647. If you assign more value than max range value then you get count started from min value. That is if you assign 2147483650 then you get -2147483646.
Because of bits value of more than 4bytes fitting positions are not retrieved.. And minus because the last bit reserved for +ve of -ve value for signed integers.
For more simply, if a type is requires 3bits then
You can assign
000 to 111 only.. (0 to 7). (for unsigned thinking..)
If you assign 8 its byte value if 1000 will be fitted 3 bits only so it stores 000 only so it gives you 0.
For signed, last bit is for -ve or +ve then
100 to 011 that is -4 to 3 only.. So assigning 8 will stored as 000 that retrieved as 0.
For value 4(100) stored as 100 so it retrieved as -3.
This above all happens at run time.. Not at compile time.
Also note that you cannot directly add overrange value at compile time, it give you compile time error.
Hope it helps....
+ 6
Yes I know that it is an error
But it has an answer I don't know what can I find it ?
+ 5
Jayakrishna🇮🇳 thanks it is useful for me
+ 5
ChaoticDawg thanks for your help
now I know
+ 4
Thanks but I know that
With out error
The answer Jayakrishna🇮🇳 is correct you can read it
It is a tactical questions of Java
Thanks for your help
+ 4
Yes you are right it has error
But we ignore it and we assume it is not error so the answer is Jayakrishna🇮🇳 will be good answer
+ 2
This may help answer your question
https://code.sololearn.com/cvX2LFla7LVu/?ref=app
+ 1
Ghezaal Shefa if your looking for the compilation error, just look in your console.
+ 1
Ghezaal Shefa I think each data type has a specific length ^^ in java there are byte, short, int, long ,float, double so if you have a long number try to use "long"
+ 1
You're welcome Ghezaal Shefa
+ 1
You will get the out of range error.
To avoid this you have to know range of each and every data type in Java
1)byte -128(-2^7)to127(2^7-1)
2)short -32768(-2^15)to32767(2^15-1)
3)int -2147483648(-2^31)to2147483647(2^31-1)
4)long -9223372036854775808(-2^63)to9223372036854775808(2^63-1)
5)double 4.9e-324to1.8e+308
6)float 1.4e-045to3.4e+038
0
Simple, you get an error. Next time why don't you try running it to see for yourself?
0
Check in compiler
0
@VAMSI
The question is about run time assignment, not about compile time.. I added explanation about both cases clearly..
Yes it's error in
int num = 2147483650 ; this is compile time error because of overrange..
But
int num=5;
num += 2147483647; here its value is out of range of int but it will not give you error but produce wrong result..
This is what the question is about. It's not error.