Data Types in C Language
The C programming language provides three main types of data types.
- Primary Data Types
- Derived Data Types
- User-Defined Data Types
1. Primary Data Types in C Language
Primary data types are the core building blocks of the C language.
They are built-in to the language, meaning their meaning and behavior
are defined by the language itself.
These are also called basic or fundamental data types.
| Data Type | Description | Example | Size (in Bytes) |
|---|---|---|---|
| int | Integer numbers | 10, -20 | 2 or 4 bytes |
| float | Single precision decimal numbers | 10.25, -5.6 | 4 bytes |
| double | Double precision decimal numbers | 10.256789 | 8 bytes |
| char | A single character | 'A', '3' | 1 byte |
| void | No value / empty (used for functions that return nothing or unspecified type pointers) | – | 0 bytes |
| bool | Boolean values true or false | true / false | 1 byte |
2. Derived Data Types in C Language
Derived data types are created using basic data types.
Since they are formed from primary data types, they are called derived data types.
| Data Type | Usage |
|---|---|
| array | A collection of values of the same data type |
| pointer | Used to store the address of another variable |
| function | A block of code that returns a value |
3. User Defined Data Types
User-defined data types allow programmers to create their own custom data types
based on their requirements.
| Data Type | Usage |
|---|---|
| struct | Used to group variables of different data types |
| union | Used to allow different variables to share the same memory |
| enum | User-defined set of named integer constants |