What are the different data types present in C++?
-
Fundamental Data Types:
- int: Represents integers.
- float: Represents single-precision floating-point numbers.
- double: Represents double-precision floating-point numbers.
- char: Represents single characters.
- bool: Represents Boolean values (true or false).
- void: Represents the absence of type.
- wchar_t: Represents wide characters (larger character set than char).
-
Modifier Types:
These are used with the fundamental types to alter their meaning.
- signed: Makes a type store both negative and positive values.
- unsigned: Makes a type store only non-negative values.
- short: Used with int to create a smaller integer type.
- long: Used with int to create a larger integer type.
- long long: Used with int for an even larger integer type (C++11 onward).
-
Derived Data Types:
These types are derived from the fundamental data types.
- Arrays: Collection of data items of the same type.
- Pointer: Variable that stores the memory address of another variable.
- Reference: An alias for an already existing variable.
- Function: Set of statements that performs a task.
-
User-Defined Data Types:
These types allow users to define their own data types.
- enum: Enumeration, a way of defining named integer constants.
- struct: Structure, a collection of variables (possibly of different types) under a single name.
- union: Similar to struct, but all members share the same memory location.
- class: The central feature of C++ that supports Object-Oriented Programming. It can contain variables and functions.
-
Complex or Compound Data Types:
These are more advanced data types often used in C++.
- string: Represents sequences of characters (technically, it’s a class from the C++ Standard Library).
- vector, list, map, etc.: Part of the C++ Standard Template Library (STL), used for creating complex data structures like dynamic arrays, linked lists, etc.
Related Posts:
What are the differences between C++ and Java?(Opens in a new browser tab)
What are JavaScript Data Types?(Opens in a new browser tab)
Introduction to JavaScript – Review Types and Operators(Opens in a new browser tab)
A Retrospective: Diana Roy’s Invisible Majority(Opens in a new browser tab)