Difference between int and float data type

Asked By 10 points N/A Posted on -
qa-featured

What is the difference between int and float data types dealing with numbers in C++ language.

Also write a C++ program to demonstrate it.

SHARE
Best Answer by Aristono Martin
Best Answer
Best Answer
Answered By 20 points N/A #124163

Difference between int and float data type

qa-featured

Hi Eleanor,

Int and Float are both data types on C++ language. Int (integer constant) is any integer(positive or negative) number without any decimal point. Sample Int values are 5, -5, +35, 2000, etc. Float (floating constant) is any signed or unsigned number that have decimal point. Sample float values are +15.34, -7.8, +4.8950, etc.

Sample code for int value is:

                Int x,y;

                Int r,b,s;

Sample code for float

                Float mynumber

Sample code that demonstrate it:

// sample variablesvariables

 

#include <mystream>

usingnamespace std;

 

intmain ()

{

  // declaring variables:

  int c, d;

  int result;

 

  // process:

  c = 5;

  d = 2;

  c = c + 1;

  result = c – d;

 

  // print out the result:

  cout << result;

 

  // terminate the program:

  return 0;

}

 

Aristono

Answered By 0 points N/A #124164

Difference between int and float data type

qa-featured

The int and float are some of the basic fundamental data types in C++.

Int stands for Integer constant, meaning, it is any number(positive or negative) that is represented without any decimal point.
                Example: 6, -11, +26, 100
There are two types of int:

short int (short) Short Integer. 2bytes in size, with number range of, signed: -32768 to 32767 and unsigned: 0 to 65565

long int (long) Long Integer. 4bytes in size, with number range of, signed: -2147483648 to 2147483647 and unsigned: 0 to 4294967295

Float stands for Floating constant, meaning, it is any signed or unsigned numbers that is represented having decimal point.

Example: +11.735 , -7.5 , +6.628

Float Floating point number. 4bytes in size, with number range of  3.4e +/- 38 (7 digits)

Please note that the given values (size and range) are found on most 32-bit systems.

Answered By 0 points N/A #124165

Difference between int and float data type

qa-featured

The solution for your question is simple. 

Int Data Type

Integer int data type is used to store integer values like 34, 68790 etc.

To declare a variable of type integer type keyword int followed by the name of the variable. you can give any name to a variable. 

For Example:

int sum;  or     int x;

or we can give value to it like

int a=24;

This is called declaring and defining the variable of data type int.

The int data type can store both values in negative or positive. It will always b a whole number. Its Values ranges from -2,147,483,648 to 2,147,483,647. It uses 4 bytes of memory. 

Float Data Type

It is used to store decimal values or the values in fractions. Also called floating point data type. To declare the variable of floating type keyword float and the variable name. 

For example:

float Product;

float x=3.44;

This is called declaration and definition. Float has further three types. 

  • Float
  • Double
  • Long Double

Float type range is very high. it use 4 bytes of memory. 7 digits accuracy. 

 

Example Program:

#include<iostream.h>

int main()

{

             int x=34;

            float y=23.3333;

cout << "Integer Value is  " << x << endl;

cout << "Floating Value is  " << y << endl;

return 0;

}

This program simply displays output values of int data type and float data type.

Hope you fully understands the difference. 

Point to remember:

If you use int data type and gives it a decimal value like 33.33, it will only read the value before decimal and cant read the fractional value. so we use it were we want to deal with whole numbers.

And we use float type where we want to use decimal numbers.

Related Questions