fundmental data types

Hi i a little confuse about fundmental data types
For example what is the diffrence between int and long int
They both 4 bytes and with the same range of numbers
And what is the range of the 3 floating point and the diffrences
Between them
Not all machines will use 4 bytes for a long, for example my red hat enterprise server responds with an 8 when the code encounters a call to sizeof(long)

I recommend the int type if you are unsure what to use, as this is usually the natural size for the processor your code is compiled on.

According to my book, Absolute C++, the range for floats is about 10^-38 to 10^38 with 7 digit precision.

Since all of your data, regardless of their type, is stored in computer memory as 1's and 0's it comes down to how the computer will treat that information when it reads it. For example, if you #include <stdio.h> and use printf("%d", x) then the compiler will expect x to be an integral decimal representation such as an int, and output what the binary value represents assuming it is an int. However, if it is actually a float the data is stored differently and it will not output what you would expect.
Last edited on
How can i learn how the computer saving data?
Guess you will have to research it? Wikipedia maybe?

http://just2good.co.uk/bits.php
https://en.wikipedia.org/wiki/Integer_%28computer_science%29
https://en.wikipedia.org/wiki/IEEE_floating_point

also sizes of integers in C++ should follow this:
char <= short <= int <= long <= long long
Topic archived. No new replies allowed.