C Programming Tutorial – C Data Types

Previous Article
Next Article

Data types are very important concept in programming languages.You can choose the right kind of variable types for your program. The data types depends on the compiler which create machine codes suitable for 16-bit or 32-bit processors.

Sometimes when the processor has backward compatibility, then a 32-bit processor can run a 16-bit machine code successfully.

Integer Data Types

An integer data type is declared using keyword – int. We will have a separate discussion on keywords so let’s not worry about them right now.

If you think of memory, then think of sequence of bytes with an address called a memory address. A memory address is a hexadecimal value. One byte of information is 8-bit of information.

Integer Data TypesRequired Storage
int2 or 4 bytes
short int2 bytes
long int4 bytes

On a 16-bit compiler like turbo C++, the int type has requires two bytes storage and on a 32-bit compiler, storage requirement is 4 bytes.

Short int is always 2 bytes in size and long int is always 4 bytes in size.

Range of the data types

What does it mean to have a range of values ? We will explain that in a minutes. Machine codes are binary strings made of 0s and 1s. They are instructions or data for processor – Opcode or Operand.

So, the range of a data type is nothing, but number of possible binary strings that is allowed using the byte storage. In other words, ” How many numbers can you store in binary format using 2 or 4 bytes of memory space ?”
For 16-bit compiler the range is
(2^16 /2) - 1 = (65536/2) - 1 = -32768 to + 32767

For 32-bit compiler the range is


(2^32 /2) - 1 = (4294967296/2) - 1 = -2147483648 to +2147483647


Unsigned and Signed Integers

If you want all positive values then declare the int variable as unsigned. An unsigned data type disregard the sign bit, so that all the values are positive starting from 0.unsigned int for 16-bit compiler


2^16 - 1 = 65536 - 1 = Range from 0 to 65535.


unsigned int for 32-bit compiler.


2^32 - 1 = 4294967296 - 1 = Range from 0 to 4294967295.

Signed data type has both positive and negative values.

For example,


signed long int;
signed short int;

Character Data Types

The character data type takes 1 byte of storage. The signed char and char are the same.

Unsigned and Signed Characters


signed char ; /* Range from -128 to + 127 */
unsigned char; /* Range from 0 to 255 */

Each character has a number and char cannot take values greater than -128 to +127.

Float and Double Data Types

The float and the double data types take 4 bytes and 8 bytes respectively. The long double take 10 bytes of storage.

Data TypesRequired Storage
float4 bytes
double8 bytes
long double10 bytes

An Example Program

#include <stdio.h>
int main()
char p = 'a';
int s = 10;
long int q1 = 1000;
short int q2 = 223;
float b1 = 23.55;
double b2 = 33.5545;
signed char ch = 'h';
signed int g1 = -33;
unsigned char ch1 = 'D';
unsigned int g2 = 234;
unsigned long int num = 333234;
unsigned short int num2 = 2442;
printf("char = %cn", p);
printf("int = %dn",s);
printf("long int = %ldn",q1);
printf("short int =%dn",q2);
printf("float = %fn",b1);
printf("double = %fn",b2);
printf("signed char= %cn",ch);
printf("signed int = %dn", g1);
printf("unsigned char = %un",ch1);
printf("unsigned int = %un",g2);
printf("unsigned long int = %un",num);
printf("unsigned short int = %un",num2);
return 0;


Output - C Data Types
Output – C Data Types



Balagurusamy, E. 2000. Programming in ANSI C. Tata McGraw-Hill Education,.

Brian W. Kernighan, Dennis M. Ritchie. 1988. C Programming Language, 2nd Edition. Prentice Hall.


Previous Article
Next Article