C data types are classifications that specify the type of data a variable can hold. Here are the main categories:
-
Basic Data Types:
- int: Represents integer values (e.g.,
int age = 25;). - float: Represents single-precision floating-point numbers (e.g.,
float height = 1.75;). - double: Represents double-precision floating-point numbers for more precision (e.g.,
double pi = 3.14159;). - char: Represents single characters (e.g.,
char initial = 'A';).
- int: Represents integer values (e.g.,
-
Derived Data Types:
- Arrays: A collection of elements of the same type (e.g.,
int numbers[5];). - Pointers: Variables that store memory addresses (e.g.,
int *ptr;). - Structures: User-defined data types that group different data types (e.g.,
struct Person { int age; char name[50]; };). - Unions: Similar to structures but can store different data types in the same memory location (e.g.,
union Data { int i; float f; char c; };).
- Arrays: A collection of elements of the same type (e.g.,
-
Enumeration:
- enum: A user-defined type that consists of a set of named integer constants (e.g.,
enum Color { RED, GREEN, BLUE };).
- enum: A user-defined type that consists of a set of named integer constants (e.g.,
-
Void:
- void: Represents the absence of type. Used for functions that do not return a value (e.g.,
void functionName() {}).
- void: Represents the absence of type. Used for functions that do not return a value (e.g.,
Summary
Understanding these data types is essential for effective memory management and data manipulation in C programming. Each type has its own range and memory size, which can vary based on the system architecture.
If you have more questions or need examples, feel free to ask!
