C++ data types are categorized into several groups:
Basic Data Types:
- int: Represents integer values (e.g.,
int age = 25;). - float: Represents single-precision floating-point numbers (e.g.,
float salary = 50000.50;). - double: Represents double-precision floating-point numbers (e.g.,
double pi = 3.14159;). - char: Represents a single character (e.g.,
char grade = 'A';). - bool: Represents boolean values (
trueorfalse).
- 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;). - References: An alias for another variable (e.g.,
int& ref = age;).
- Arrays: A collection of elements of the same type (e.g.,
User-Defined Data Types:
- Structures: A collection of different data types grouped together (e.g.,
struct Person { int age; char name[50]; };). - Classes: A blueprint for creating objects, encapsulating data and functions (e.g.,
class Car { public: int speed; };). - Unions: Similar to structures but can store different data types in the same memory location (e.g.,
union Data { int intVal; float floatVal; };). - Enumerations: A user-defined type consisting of a set of named integral constants (e.g.,
enum Color { RED, GREEN, BLUE };).
- Structures: A collection of different data types grouped together (e.g.,
Understanding these data types is essential for effective programming in C++. If you want to dive deeper into any specific type or concept, let me know!
