Primitive Data Types
Published by
sanya sanya
What are all 7 primitive datatypes in C++?
There are several primitive data types that are built into the language.
1. Boolean (‘bool’): Represents a logical value and can have two possible states: ‘true’ or ‘false’. It is typically used for conditional statements and Boolean expressions. The size of a ‘bool’ is implementation-defined, but it is usually 1 byte.
2. Character (‘char’): Represents a single character or a small integer value. It can hold characters from the ASCII character set or extended character sets like Unicode. The size of a ‘char’ is 1 byte.
3. Integer types (‘int’, ‘short’, ‘long’, ‘long long’): Represent whole numbers without decimal points. The different integer types provide varying ranges of values they can hold. The sizes of these types depend on the compiler and platform:
- ‘int’: Typically represents a signed integer. The size is usually 4 bytes.
- ‘short’: Represents a shorter signed integer. The size is usually 2 bytes.
- ‘long’: Represents a longer signed integer. The size is usually 4 bytes.
- ‘long long’: Represents a longer signed integer with a larger range. The size is usually 8 bytes.
4. Floating-Point types (‘float’, ‘double’): Represent decimal numbers (real numbers) with single or double precision. Floating-point types can store both small and large values. The sizes of these types depend on the compiler and platform:
- ‘float’: Represents single-precision floating-point numbers. The size is usually 4 bytes.
- ‘double’: Represents double-precision floating-point numbers. The size is usually 8 bytes.
5. Void (‘void’): Denotes the absence of a type. It is commonly used as the return type for functions that do not return a value, or to indicate an empty argument list.
It's important to note that the sizes mentioned are typical, but they may vary depending on the compiler, platform, and implementation.
Library
WEB DEVELOPMENT
FAANG QUESTIONS