Data Types in C Programming (Complete Guide with Examples)
This tutorial explains data types in C programming, which define the type and size of data a variable can store. It covers basic, derived, and user-defined data types with syntax and examples to help beginners understand memory usage and correct data representation in C programs.
1. What Are Data Types in C
Data types specify:
- The type of data a variable can store
- The amount of memory allocated
- The operations that can be performed on the data
2. Classification of Data Types in C
C data types are broadly classified into:
- Basic (Primary) Data Types
- Derived Data Types
- User-defined Data Types
3. Basic (Primary) Data Types
3.1 int
Used to store whole numbers.
Typical size: 4 bytes
3.2 float
Used to store decimal values with single precision.
Typical size: 4 bytes
3.3 double
Used to store decimal values with double precision.
Typical size: 8 bytes
3.4 char
Used to store a single character.
Typical size: 1 byte
Example Program (Basic Data Types)
4. Type Modifiers
Type modifiers change the size or range of basic data types.
Modifiers:
shortlongsignedunsigned
Examples
5. Derived Data Types
Derived data types are created using basic data types.
5.1 Arrays
5.2 Pointers
5.3 Functions
6. User-defined Data Types
6.1 struct
6.2 union
6.3 enum
6.4 typedef
7. void Data Type
void represents the absence of a value.
Example:
8. Size of Data Types
Use sizeof operator to find memory size.
Key Points to Remember
- Choose correct data type to optimize memory
- Use
sizeofto verify memory usage - Understand type modifiers for system-level programming