C Data Types

A data type is a classification that specifies which type of value a variable can store.

  • We need to define data types of each variable during variable declaration.
  • Each data types requires different amount of memory storage.
  • The data type of a variable also determines that what kind of operation can be performed on variable data.

TypesData Types
1.Basic data typesint, char, float, double
2.Derived data typepointer, array, structure, union
3.Enumeration data typeenum
4.Void data typevoid

C Data Types

C Language has some predefined set of data types to handle various kinds of data in any program. There are four basic data types that can be associated with variables in C.


Basic Data Type

The basic data types in C are integer (int), floating (float), character (char) and double. These are also called fundamental data types or primary data types.

The memory storage of basic data types can be different in 32 or 64-bit operating system.


Integer type

Integer data type allows a variable to store some range of mathematical numbers. Integer data types are declared using ‘int’ keyword. The storage size of integer data type can be 2, 4 or 8 byte. It mainly depends upon the processor in the CPU.

C language supports both signed and unsigned literals. Integers are able to store whole numbers only. Therefore, decimal values can not be stored in integers. Example of Integers are: 2, 50, 1000, 23954.

Types of integer type

TypeSizeRange
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

Floating Type

Float data type can store decimal values to a variable. Storage size of float data type is often 4 and it can vary depending upon the processor in the CPU. In float data type, we can use up-to 6 digits after decimal.

Floating type variables can hold real numbers such as: 1.5, -4.123, 20.0 etc.


Double

Double data type stores decimal values similar to float data type but it can store up-to 10 digits after decimal. The range for double datatype is from 1E–37 to 1E+37.

TypeStorageValue rangeDecimal Points
float4 byte1.2E-38 to 3.4E+386 decimal places
double8 byte2.3E-308 to 1.7E+30815 decimal places
long double10 byte3.4E-4932 to 1.1E+493219 decimal places

Character Type

Character data type is used to store only one character to a variable. ‘char’ keyword is used to define character data type in C programming. Storage size of character data type is 1.

Example of Char data types are: ‘a’,’b’,’x’,’y’.

Types of Character Type

TypeSizeRange
char1 byte−128 to 127
singed char1 byte−128 to 127
unsigned char1 byte0 to 255

Void Data type

Void data type mostly used to specify the type of functions & pointers. Void simply means empty or no value.

In C language, some functions do not return any value. We can use void data type for those functions as a return type. Example of void data type is: void mytask();


There are few more data type which we will cover in details. You can learn about them in next chapters.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.