Float and Ints

Floats( float ) and integers( int ) are two widely used datatypes in programming environments.

  • An integer is an integral data type used to store whole numbers.

  • A float has the ability to store decimal or floating-point​ numbers.

svg viewer
Float Int
Size 32 bits 32 bits
Range 1.2 x 10-38 to 3.4 x 1038 -2,147,483,648 to 2,147,483,647
Example 2.4, 3.8, 11.2 1,22,55

Code

Thefloat and int datatypes are a little bit different. Here is a sample code for a better understanding.

In the example above, integer variable a and float c prints the exact value as assigned to it; whereas, b is an integer variable and only stores 9 instead of 9.5.

#include <iostream>
using namespace std;
int main() {
// Integer whole number assigned to int a
int a = 5;
// Floating point number assigned to an integer value b.
// It will store the value before decimal i.e 9
int b = 9.5;
//Floating point number assigned to float c.
float c = 7.8;
//output can be seen with cout command.
cout << a <<endl << b << endl << c <<endl;
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved