Wednesday 23 November 2016

What is data type and types in C++ ?

Data Type:

Data type defines a type of a variable or a value. The data is stored in a variable is according to its data type otherwise, it will generate an error.

There are main data types:


  1.     int (integer)
  2.     char (character)
  3.     float
  4.     Boolean

int data type:

int datatype is used to store the integers. It allows a variable to store an integer value. Both negative and positive numbers can be assigned to int datatype but it does not support floating values.

Example:

int roll_no = 5;
int a=-18;

char data type:

char data type is used to store a character. One character will use a 1 bit of memory.
A character is enclosed in single-quotation [‘ ‘].

Example: 

char s = ’a’;

float data type:

float datatype is used to store a numeric value with a fraction or can point value. It allows both negative and positive  numbers as well as floating values.

Example:

float  height = 5.5647;
float radius = 2.8931;

Boolean data type:

Boolean datatype has only two value “true” and “false”.  It is used for conditional statements. A Boolean variable cannot store number, integer and any other values except “true” and “false”.

No comments:

Post a Comment