0

Why the value is not same?

#include <iostream> using namespace std; int main() { int x=3456789011; cout <<x; return 0; }

9th Aug 2017, 4:11 PM
Core i9
Core i9 - avatar
3 ответов
+ 5
In C, the integer (for 32 bit machine) is 32 bits, and it ranges from -32768 to +32767. In Java, the integer is also 32 bits, but ranges from -2,147,483,648 to +2,147,483,647. the number you are giving is out of range it is deducting max range and showing you remaining number
9th Aug 2017, 4:14 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 4
@Melih Out of curiosity, what makes C's int such a small range when it uses the same amount of memory compared to Java? Does an integer only occupy 16 bits unless instructed to occupy 32?
9th Aug 2017, 4:31 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
because the range of the integer type is from -2147483648~2147483647. you can use sizeof () to see why is that range
9th Aug 2017, 4:15 PM
懵懂蔡
懵懂蔡 - avatar