Senin, 21 Oktober 2013

Basic or Simple or Primitive data types in C programming

Introduction

Definition : “Basic data types are those that are not composed of other data types.

Primitive Data types are:

  • int
  • char
  • float
  • double
  • void
Note: The primitive data types are also called basic data types or simple data types or
fundamental data types.

int

It is a keyword which is used to define integer numbers. Normally they are associated with the
Variables to store singed integer values in memory  locations. That is, using this data type both
Positive and negative numbers can be stored in the memory . To represent only unsigned numbers
it is normally associated with a qualifier unsigned.
For example, unsigned int is used to define only positive numbers. Negative numbers cannot be
Stored if a variable is associated with unsigned int. the size and the range of integer vary from
Machine to machine as shown below:


n- bit machine
Size of int
Range of unsigned int
0 to 2n -1
Range of signed int
-2n-1 to 2n-1 -1
16-bit machine
2 bytes
0 to 216-1
Or
0 to 65532
-215 to 215-1
Or
-32768 to 32767
32-bit machine
4 bytes
0 to 232-1
Or
0 to 4294967295
-231 to 231 -1
Or
-2147483648 to 2147483647


Float

 It is a keyword which is used to define floating point numbers. The floating point numbers are Also called real numbers. Normally they are associated with the variables (also called identifiers) To store floating point numbers in memory locations. That is , using this data type both positive And  negative floating point numbers can be stored in the memory.

 Double

It is a keyword which is used to define  high precision floating point numbers Normally they are       Associated with the variables to store large floating point numbers in memory locations. That is, Using this data type both positive and negative large floating point numbers can be stored in the Memory.

Char

 It is a keyword which is used to define single character or a sequence of character called string.
Normally , They are associated with the variables to store a character or a string  in  memory
Locations. Each character stored in the memory is associated with a unique value called an ASCII
(American standard Code For Information Interchange) value.

Void

It is an empty data type. It is normally used in functions to indicate that the function does not
Return any value. Since no value is associated with this data type, it does not occupy any space
in the memory. Normally, it is not associated any variable (except pointers).

Table- Size and Range of Data types on a 10-bit machine.

Type
Size (bits)
Range
Format
Char of signed char
Unsigned char
Short signed int
Shot unsigned int
Signed int
unsigned int
long signed int or long int
long unsigned int
Float
double
long double
8
8
16
16
16
16
32
32
32
64
80
-128 to 127
0 to 255
-32768 to +32767
0 to65535
-32768 to +32767
0 to 65535
-2147483648 to +2147483647
   0 to 429467295
-3.4e38 to +3.4e38
-1.7e308 to +1.7e308
-1.7e4932 to +1.7e4932
%c
%c
%d
%u
%d
%u
%ld
%lu
%f
%lf
% lf

Tidak ada komentar:

Posting Komentar