Data Types in C with examples and Size of Data Types

Data Types in C is very important concept to understand along with the size of Data Types in C. So In this article, I will be providing an information about Data Types in C with examples and Size of Data Types.

Data types refer to an extensive system used for declaring variables or functions of different types before its use. To represent different types of data in C program we need different data types.

The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The value of a variable can be changed any time.


C supports four different classes of data types namely:

Types of Data Types in C


TypesData Types
Basic Data Typeint, char, float, double
Derived Data Typearray, pointer, structure, union
Enumeration Data Typeenum
Void Data Typevoid




BASIC DATA TYPES in C


All arithmetic operations such as Addition , subtraction etc are possible on basic data types.

E.g.: 
    int a,b; 
    Char c;

The following table shows the Storage size and Range of basic data type:

Size of Data Types

Size is given according to 32-bit architecture.

Data TypesMemory SizeRange
char1 byte−128 to 127
signed char1 byte−128 to 127
unsigned char1 byte0 to 255
short2 byte−32,768 to 32,767
signed short2 byte−32,768 to 32,767
unsigned short2 byte0 to 65,535
int2 byte−32,768 to 32,767
signed int2 byte−32,768 to 32,767
unsigned int2 byte0 to 65,535
short int2 byte−32,768 to 32,767
signed short int2 byte−32,768 to 32,767
unsigned short int2 byte0 to 65,535
long int4 byte-2,147,483,648 to 2,147,483,647
signed long int4 byte-2,147,483,648 to 2,147,483,647
unsigned long int4 byte0 to 4,294,967,295
float4 byte3.4*10E-38 to 3.4*10E38
double8 byte1.7*10E-308 to 1.7*10E308
long double10 byte3.4*10E-4932 to 1.1*10E4932


Now, next data types in C.

DERIVED DATA TYPES in C

Derived datatypes are used in ‘C’ to store a set of data values. Arrays and Structures are examples for derived data types.

Ex: 
    int a[10];
    Char name[20];


USER DEFINED DATATYPES in C


C Provides a facility called typedef for creating new data type names defined by the user. For Example ,the declaration.

 typedef int Integer;
Makes the name Integer a synonym of int.Now the type Integer can be used in declarations ,casts,etc,like,

 Integer num1,num2;

Which will be treated by the C compiler as the declaration of num1,num2as int variables. “typedef” ia more useful with structures and pointers.

POINTER DATA TYPES in C


Pointer data type is necessary to store the address of a variable.

Comments

Popular posts from this blog

Implement Bouncing Ball Animation Using C Graphics

Walking Stickman -Using C graphics

Sine Wave - Using C Graphics