Programming Concepts Lec-03_1
Programming Concepts Lec-03_1
Lec-03
By
Amjad Khan Khalil
[email protected]
What is Data type?
Data types specify the type of value that
will be stored in a particular variable.
Usually data types of a variable gives the
following two types of information to the
compiler.
It specify the type of value that will be stored
at a particular variable.
It also specify the storage space that the
int var1;
int var2 = 10;
The above two statements are known as
variable declaration.
In the second statement, we declared a
variable and also gave it initial value
which is called variable initialization.
Basic data types
The following three are basic data
types and all other data types are
being derived from these three
basic data types.
Char (character)
Int (integer)
Float (real or floating which consist of
decimal point)
char
This keyword is used to declare characters.
The size of each character is 8 bits. i.e., 1
byte. The characters that can be used with this
data type are ASCII characters. A variable of
type character can be declared as follow:
char ch;
sign char bcs = ‘H’;
The maximum value that we can store at
character type variable is
from -128 to 127
Unsigned char
This is derived data type of variable
which show that the value store at
a variable will always be positive.
A variable of type unsigned can be
declared as
Unsigned char bcs;
The rang of unsigned character will be
from 0 to 255
int
This int keyword is used to declare
integers, whole numbers either positive
or negative. Most of the compilers treat
this with a size of 2 bytes. i.e., integer of
16 bits length. The following statement
shows how the variables of int type are
declared.
int var1;
The rang of values that we can store in
two bytes is from-32768 to 32767
Unsigned int
If we want that the value store at
integer variable will always be
positive then we use the keyword
unsigned with int as follow.
Unsigned int var;
Then the range of values that can be
stored at this type of variable will be
From 0 to 65536.
Long
If the value we want to store at integer
variable exceeds from 65536 then we
use the long data type for that variable.
This long keyword is used for
declaring longer numbers. i.e, numbers
of length 32 bits or 4 bytes.
for singed long the range of values will
be from -2147483648 to 2147483647
For unsigned long the range of values
will be from 0 to 4294967295
float
This keyword float is used to declare
floating point decimal numbers. A
sample declaration would be,
float var2;
For float data type the compiler will
also reserved 4 bytes. The range of
values that we can store at float
variable is from -3.4×1038 3.4×1038
double
It is also a floating point number
but the compiler will reserve 8
bytes space in memory.
double var;
The range of values that we can
store at double data type variable is
From -1.7×10308
To 1.7×10308
Long double
If we want to store a greater value
then C++ provides us the facility to
declare the type of a floating
variable as long double.
For long double data type the
compiler will reserve 10 bytes of
space
It can be declared as
long double var;