Friday, 29 May 2015

Data Types In C

By
In c programming language any of the data should be declare before it can be used in program. Data types in c are used for assigning a type to a data. Data Types of any variable define how much space occupies in memory storage.

Data Types In C

Data types in c can be classified as follows :
      
                  1)      Basic Data Types
·         Integer types
·         Floating Point Types
·         Character Types
                 2)      Derived Data Types
·         Arrays
·         Pointer
·         Structures
·         Union Types
·         Function Types

Integer Data Types

Integer data types is used when the declare variable with integer type. We can declare integer data type using the “int keyword.

Example

int abc;
Here, int is integer data type and abc is the variable.

Following detail about integer types with storage sizes and value ranges. 

Data Type


Storage Size

Value Range
Char
1 byte
-128 to 127 or 0 to 255
unsigned Char
1 byte
0 to 255
signed Char
1 byte
-128 to 127
int
2 or 4 bytes
-32,768 to 32767
unsigned int
2 or 4 bytes
0 to 65,535
Short
2 bytes
-32,768 to 37,767
unsigned short
2 bytes
0 to 65,535
Long
4 bytes
-2,147,483,648 to 2,147,483,647
unsigned long
4 bytes
0 to 4,294,967,295

Floating-Point  Data types

Floating point data type stored floating point values such as 1.25, -65.20, 0.55 etc. We can declare floating point data types using “float” or “double” keyword.

Example

float abc1;
double abc2;

Here float and double are floating point data types define and abc1 and abc2 are variable. Main difference between float and double are sizes because float size is 4 bytes and double size is 8 bytes.

Following detail about floating-point types with storage sizes and value ranges.

Data Type


Storage Size

Value Range
float
4 bytes
1.2E-38 to 3.4E+38
double
8 bytes
2.3E-308 to 1.7E+308
long double
10 bytes
3.4E-4932 to 1.1E+4932

If we want to get exact size of the data types in c language so we use the sizeof operator. Sizeof operator return the size of data types.

Example

#include <stdio.h>
#include <float.h>
 int main()
{
printf(“Size of integer type is  :  %d \n”, sizeof(int));
printf(“Size of float type is : %d” , sizeof(float));
return 0;
}

Output

Size of integer type is  :  4
Size of float type is  :  4

0 comments:

Post a Comment