C Numeric Variable Types Integer, Long, Float – POFTUT

# C Numeric Variable Types Integer, Long, Float

[rps-include post=6557]

As we learn variables are used to store values and variables have type. Type provides information about the value hold in the variable. Numeric types used to hold numerical data like 3 , 3.5 , 23.354354646 etc. Numerical types provides simplicity and performance while making mathematical operations. There are 5 different numerical types. Here we go

# Integer

Integers are normal counting numbers. To specify a variable type as integer we use int before variable name. Integer variables require generally 4 byte memory to hold data. Integer variables can hold values between-2,147,483,648 to 2,147,483,647 . Here is some example about integer.

`int age=25;`

Here we have created an integer variable named age which holds value 25

# Short

Short type is used variable those will hold lower  numbers versus integer. Short type specifier is same with the type name as short . Short variables require 2 byte to hold in memory. Short number range  is between -32,768 and 32,767 .

`short length=180;`

We have created a short type variable named length with value 180

# Long

Long is used to hold more than integer values long requires 4 byte for memory and holds between -2,147,483,648 to 2,147,483,647 .

`long total=12314235345;`

Variable named total holds value 12314235345 which is a long type.

# Float

Float variable type is different from above variable types because above types used only counting numbers. If we want to use floating numbers float is the type we will use. Here is some floating number examples 1.0 , 123.345345, 34355.54 etc. Float variables requires 4 byte memory and hold values between 1.2E-38 to 3.4E+38 which is equal 6 decimal places.

`float percentage=123.123;`

Variable named percentage holds 123.123 which’s type is float.

# Double

Double is similar to the float type but double have double capacity according to  float. so double variables will use 8 byte memory and will hold values between. 2.3E-308 to 1.7E+308 which is equivalent 15 decimal places.

`double percentage=123.12345345343;`

Variable named percentage holds 123.123 which’s type is double.

# Float vs Double

Float and double variables types both hold float numbers. Why shouldn’t we use all ways double to make development more easy and less error prone? Because double requires more memory and using all ways double variables will be a bad practice for memory management.

[rps-include post=6557]