Data types in c

DATA TYPES IN C

0  0 2016-09-22 02:56:39

Data types are used for declaring different types of variables and functions. This type of variable determines that how much space it taking in storage.
The types in C can be classified as follows −
Types & Description
    
1.Basic Types: - This is arithmetic type.
It is classified into 2 types –
a.Integer types
b.Floating point Types

2.Enumerated types: - This is also arithmetic types and used to define variables that used to assign certain type of discrete integer values.
 
3.Void type:- This type of data type indicates that there is no value available for return.
    
4.Derived types :- Derived types list are
(a) Pointer types,
(b) Array types,  
(c) Structure types,
(d) Union types and
(e) Function types.     

Integer Types:
Following Table showing standard integer types and size with their range –
S.no     Type                    Size in bytes                      Range
1           Char                            1                      -128   to  127
2           unsigned char              1                           0   to  255
3           signed char                  1                      -128   to  127
4           int                               2                  -32,768   to  32,767
5           unsigned int                 2                           0   to  65,535
6           short                           2                  -32,768   to  32,767
7           unsigned short             2                           0   to  65,535
8           long                            4       -2,147,483,648   to   2,147,483,647
9           unsigned long              4                           0   to  4,294,967,295

Sizeof() operator :
To get the size of a type, sizeof() operator is used.
#include <stdio.h>
#include<conio.h>
#include <limits.h>

int main()
{
    int a=5;
    printf("size for int is : %d ", sizeof(int));
    return 0;
}

Output : size for int is : 2

Floating-Point Types
Following Table showing standard floating-point types and size with their range –

S. no    Type              Size in bytes                 Range                   Precision
1           float                     4                 1.2E-38  to  3.4E+38             6
2          double                  8                2.3E-308  to  1.7E+308          15
3         long double           10             3.4E-4932  to  1.1E+4932         19

Ex.
The header file <float.h> is used to allow to use values and other details of  binary representation of real numbers in programs.
The following example show that the storage space taken by a float type and its range values −
#include <stdio.h>
#include<conio.h>
#include <float.h>

int main()
{
    float min,max,dig;
    printf("size for float : %d \n", sizeof(float));
    printf("Minimum float positive value: %f\n", min );
    printf("Maximum float positive value: %f\n", max );
    printf("float place value: %d\n", dig );
    return 0;
}

The void Type
This void type used to specify that there is no value available to return.
Three kinds of situations of void type –
1.Function returns as void: There are various functions, they don’t return any value or return void. A function has no return value, has the return type as void.
Ex. void exit (int a);

2.Function arguments as void: A function that do not accept any parameter. This function accepts a void.
Ex. int rand(void);

3.Pointers to void: This (pointer of type void *) represents the address of an object, but not its type.
EX.  a memory allocation function void *malloc( size_t size );
returns a pointer to void .

 

Comments (0)

Post Your Comments

Headquarter



Hong Kong Office



Find Us On

Ziuby
Ziuby