int

We can use int for declaring an integer variable:

int num;
TypeStorage sizeValue range
Char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
Int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
Short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
Long4 bytes-2,147,483,648 to 2,147,483,647
unsigned long4 bytes0 to 4,294,967,295

To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.

float

float num;

In C, floating-point numbers can also be represented in exponential. For example:

float normalizationFactor = 22.442e2;
TypeStorage sizeValue rangePrecision
float4 byte1.2E-38 to 3.4E+386 decimal places
double8 byte2.3E-308 to 1.7E+30815 decimal places
long double10 byte3.4E-4932 to 1.1E+493219 decimal places

Set Decimal Precision

You have probably already noticed that if you print a floating point number, the output will show many digits after the decimal point:

Example:

float myFloatNum = 3.5;  
double myDoubleNum = 19.99;  
  
printf("%f\n", myFloatNum); // Outputs 3.500000  
printf("%lf", myDoubleNum); // Outputs 19.990000

If you want to remove the extra zeros (set decimal precision), you can use a dot (.) followed by a number that specifies how many digits that should be shown after the decimal point:

Example:

float myFloatNum = 3.5;  
  
printf("%f\n", myFloatNum); // Default will show 6 digits after the decimal point  
printf("%.1f\n", myFloatNum); // Only show 1 digit  
printf("%.2f\n", myFloatNum); // Only show 2 digits  
printf("%.4f", myFloatNum);   // Only show 4 digits

Aritmetic operations on numbers

C Arithmetic Operators C Increment and Decrement Operators

Type Conversation

C Num Type Conversion

Number Comparioson

C Comparison Operators

Number

C Assignment Operators