C++ Basic Programming 3

Fundamental data types

Variable:
A variable is a named storage location whose value can change.


Basic/Fundamental data types in “C++” language

int
float
double
char

int

A variable of type int can store a numeric value without decimal (without fractions).

Size : 2 byte
Range : -32768 to 32767
Example :
int a,b,c;
int roll;

float

A variable of type float can store a numeric value with decimal.

Size: 4 byte
Range : 3.4e-38 to 3.4e+38
: 3.4*10-38 to 3.4*10+38

Example:
float x,y,z;
float per;

double

A variable of type double can store a numeric value with decimal.

Size: 8 byte
Range: 1.7e-308 to 1.7e+308

Example:
double a1,a2;
The range of double is much larger as compared to float.

Char

A variable of type char can store alphanumeric value.

Size: 1 byte
Range: -128 to 127
0 to 255
can be used in two ways

(i).
char n;
can store only a single character
(ii). char n[20];
(20: represents the size, can be anything as per requirement)

can store a group of characters
This is known as a character array or string.

void:
(void empty set and non-returning functions):
void data type specifies an empty set of values. It is used as the return type for functions that do not return a value. No object of type void may be declared.