A data type in C specifies the type of data a variable can hold, such as integers, floating-point numbers, characters, etc. It also defines the size, range, and operations allowed on that data.
๐ถ Types of Data Types in C
C language has the following main categories of data types:
1. Primary (Fundamental) Data Types
2. Derived Data Types
3. User-defined Data Types
4. Void Data Type
โ 1. Primary (Fundamental) Data Types
These are the basic built-in data types provided by the C language.
Data Type
Size (in bytes)
Format Specifier
Example
Description
int
2 or 4
%d or %i
int a = 10;
Stores integers
float
4
%f
float x = 2.5;
Stores decimal numbers (single precision)
double
8
%lf
double y = 3.14159;
Stores decimal numbers (double precision)
char
1
%c
char ch = 'A';
Stores a single character
โ ๏ธ Size may vary depending on compiler and system (e.g., 32-bit vs 64-bit).
๐น Integer Types in Detail
Type
Size (Bytes)
Range (Approx)
Format Specifier
int
4
-2,147,483,648 to 2,147,483,647
%d
short int
2
-32,768 to 32,767
%hd
long int
4 or 8
-2^31 to 2^31-1 or more
%ld
unsigned int
4
0 to 4,294,967,295
%u
๐น Floating Point Types
Type
Size (Bytes)
Precision
Format Specifier
float
4
6-7 digits
%f
double
8
15-16 digits
%lf
long double
10 or 12
>16 digits
%Lf
๐น Character Type
Type
Size (Bytes)
Range
Format Specifier
char
1
-128 to 127 (signed)
%c
unsigned char
1
0 to 255
%c
โ 2. Derived Data Types
These are based on the fundamental data types.
Type
Description
Example
Array
Collection of same data types
int arr[10];
Pointer
Stores memory address of variable
int *ptr = &a;
Function
Returns data after execution
int add(int x, int y);
Structure
Groups different data types
struct Student {int id; char name[20];};
โ 3. User-defined Data Types
These are defined by the programmer using built-in types.
Type
Description
Syntax Example
typedef
Creates alias for data type
typedef int Number;
enum
Defines a set of named integer constants
enum Color {RED, GREEN, BLUE};
struct
Combines variables of different types
struct Person {char name[20]; int age;};
union
Similar to struct but shares memory
union Data {int i; float f;};
โ 4. Void Data Type
Type
Description
Example
void
Represents absence of value (no return type)
void display();
Used for:
Functions with no return (void main())
Void pointers (void *ptr)
๐งช Examples in C Code
#include <stdio.h>
int main() {
int a = 10;
float b = 5.75;
char c = 'Z';
double d = 3.14159265359;
printf("Integer: %d\n", a);
printf("Float: %f\n", b);
printf("Character: %c\n", c);
printf("Double: %lf\n", d);
return 0;
}
๐ฅ Output:
Integer: 10
Float: 5.750000
Character: Z
Double: 3.141593