RUN

# float Vs int

Written By -

float Vs int :
As we all know words are the most important part while writing any sentence in any language. Thus, data types are to any programming language. Different programming language have different types of data types and some language also don’t have these data types. But, if we talk about C and C++ they have the similar kinds of data types. These may different for different types of variables used in program. Like for an alphabet or a character, it has “char”, for numbers it has “int/float”, for long words it has “string”.
So, now we are going to compare two of the most used data types for the numbers being defined in any program, which are “int” and “float”.
Let’s consider the first one first. int, as the name signifies integer, in this type of data type we can only store integer value. Which means, no decimal value can be stored in this type of data type. It has a range from -32768 to 32768. Which means in total 65536 number value could be store in an int variable being defined. It occupies only 2 bytes in the memory. Now coming on the latter one. Float, as the name says floating point number, which means decimal + integer, and any type of number could be stored in it. Float ranges from 1.E-38 to 3.4E+38. It takes 4 bytes in memory.
Now, let’s start a comparison between the two-:
1. Int don’t have the fractional parts while storing the number in the variable, they store the whole number and round off the decimal number to the whole number. Whereas, float stores the decimal number up to 7 decimal digit.
2. There could be three number system being represented by the int data types that are octal, hexadecimal, and decimal, whereas float only stores the decimal number system.
3. Int stores the variables in the 32-bit array, where last position is being assigned for the sign bit, where as in float the storing bit array is same, but the allocation is different. From 24-31 it stores the exponent part, which is the decimal value and last bit is used for the sign bit.
4. Int is used for the smaller calculation, whereas float is used for the longer ones.
5. Int are written generally as we write a number, eg- 7, 8 etc. Whereas float is written with the mantissa and exponent part, which means decimal and integer part, eg- 2e-14, where “e” is the exponent part.
As the concluding statement, in the programming languages int is more preferred for fast computations and less time taking processes. While, float is preferred for complex calculations.