codescracker


c

C Data Types



« Previous Tutorial Next Tutorial »


Data types is simply used to declared variables or the functions. The variable type specifies that how much space it will occupy in the storage and how the bit pattern stored is interpreted. C defines the following five basic data types:

Except the type void, the basic data types may have various modifiers preceding them. A type modifier changes the meaning of the base type to more precisely fit a specific need. Here is the list of modifiers:

The int base type can be modified by signed, short, long, and unsigned. And the char type can be modified by signed and unsigned. You may also apply long to double.

C Data Types with Size and their Ranges

Following table lists all the data types with their sizes and ranges :

Type Storage Size (in Bytes) Minimal Range
char 1 -127 to 127
unsigned char 1 0 to 255
signed char 1 -127 to 127
int 2 or 4 -32,767 to 32,767
unsigned int 2 or 4 0 to 65,535
signed int 2 or 4 -32,767 to 32,767
short int 2 -32,767 to 32,767
unsigned short int 2 0 to 65,535
signed short int 2 -32,767 to 32,767
long int 4 -2,147,483,647 to 2,147,483,647
long long int 8 -(263-1) to 263-1
signed long int 4 -2,147,483,647 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295
unsigned long long int 8 264-1
float 4 1E-37 to 1E+37(six digits of precision)
double 8 1E-37 to 1E+37(ten digits of precision)
long double 10 1E-37 to 1E+37(ten digits of precision)

Signed integers are important for a great many algorithms, but they only have half the absolute magnitude of their unsigned relatives. For instance, here 32,767 in binary is:

0 1 1 1 1 1 1 1   1 1 1 1 1 1 1 1

When type modifier doesn't precede a basic type, then int is assumed. Let's look at the following table:

specifier is same as
signed signed int
unsigned unsigned int
long long int
short short int

Get Exact Size of Any Data Type in C

Since int data type has the different size on the different platform, so to get the exact or actual size of an int type or an int type variable on a particular platform, use the sizeof operator. The expressions sizeof(type) i.e., sizeof(int) tells the storage size of an object or type in bytes. Following example shows how to get the exact size of an int type on any platform:

#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr();

	printf("Storage size of int: %d\n", sizeof(int));
   
	getch();
}

Here is the sample output of the above C program:

c data types

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test