CodesJava

Easy learning with example program codes

Data Types in c


C Data Types are used to define the type of data that is to be stored. C data types can be classified into 4 groups:

● Basic Data Types:

  1. Integer
  2. Float
  3. Double
  4. Character

● Derived Data Types:

  1. Array
  2. Pointer
  3. Structure
  4. Union

● Enumeration Data Types:

  1. Enum

●  Void Data Types:

  1. Void

Basic Data Types:

 Integer: All the non-decimal numbers are called as Integers. Various forms of integers are listed below.

Data Types SIZE (Byte)

For 32 bit

RANGE
short 2 −32,768 to 32,767
signed short 2 −32,768 to 32,767
unsigned short 2 0 to 65,535
int 2 −32,768 to 32,767
signed int 2 −32,768 to 32,767
unsigned int 2 0 to 65,535
short int 2 −32,768 to 32,767
signed short int 2 −32,768 to 32,767
unsigned short int 2 0 to 65,535
long int 4 -2,147,483,648 to 2,147,483,647
signed long  int 4 -2,147,483,648 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295

Float:

Float represents all the decimal and exponential numbers. The float size is of 4 bytes.

Double:

Double also represents all the decimal and exponential numbers. Various forms of double are listed below.

Data Types SIZE (Byte) For 32 bit
double 8
long double 10

Character:

Various forms of characters are listed below.

Data Types SIZE (Byte) RANGE
char 1 −128 to 127
signed char 1 −128 to 127
unsigned char 1 0 to 255

 

Example:

#include<stdio.h>
 
void main()
{
printf ("For 64 bit architecture\n");
printf ("\nSize of int: %d", sizeof(int));
printf ("\nSize of short: %d", sizeof(short));
printf ("\nSize of short int: %d", sizeof(short int));
printf ("\nSize of long int: %d", sizeof(long int));
printf ("\nSize of char: %d", sizeof(char));
printf ("\nSize of float: %d", sizeof(float));
printf ("\nSize of double: %d", sizeof(double));
printf ("\nSize of long double: %d", sizeof(long double));
}

Output

For 64 bit architecture                                                                                                                
 
Size of int: 4                                                                                                                         
Size of short: 2                                                                                                                       
Size of short int: 2                                                                                                                   
Size of long int: 8                                                                                                                    
Size of char: 1                                                                                                                        
Size of float: 4                                                                                                                       
Size of double: 8                                                                                                                      
Size of long double: 16
Posted in C   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki