- C Programming Basics
- C Tutorial
- C Program Structure
- C Basic Syntax
- C Data Types
- C Constants
- C Variables
- C Operators
- C Ternary Operator
- C Storage Classes
- C Flow of Control
- C Decision Making
- C if if-else Statement
- C switch Statement
- C Loops
- C for Loop
- C while Loop
- C do-while Loop
- C goto Statement
- C break Statement
- C continue Statement
- C Popular Topics
- C Arrays
- C Strings
- C Pointers
- C Functions
- C Recursion
- C Scope Rules
- C Programming Advance
- C Structures
- C Unions
- C Bit Fields
- C Enumerations
- C Input & Output
- C Typedef
- C Preprocessors
- C Type Casting
- C Recursion
- C Error Handling
- C Linked Lists
- C Stacks
- C Queues
- C Binary Trees
- C Header Files
- C File I/O
- C Variable Arguments
- C Memory Management
- C Command Line Arguments
- C Programming Examples
- C Programming Examples
- C Programming Test
- C Programming Test
C Data Types
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:
- character - declared using char
- integer - declared using int
- floating-point - declared using float
- double floating-point - declared using double
- valueless - declared using void
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:
- signed
- unsigned
- long
- short
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:

« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube