Reputation: 153
I know that it might not be important to know but it's purely based on my curiosity. I've looked everywhere on the internet and every website had different numbers which was really frustrating. this website (https://en.cppreference.com/w/cpp/language/types) shows 28 primitive data types for C++ while others show different numbers. Can anyone help me with this?
Upvotes: 2
Views: 3579
Reputation: 138201
"Primitive data type" is not a term that the standard specifies, so you might get a different answer depending on who you ask. Clang defines the following types as "built-in", meaning that they aren't derived from any other type:
void
bool
std::nullptr_t
float
double
long double
char16_t
char32_t
signed
and unsigned
variants of:
char
wchar_t
short
int
long
long long
The list contains more, but I believe that those are the only ones that are specified in standard C++.
The standard has essentially the same thing in [basic.fundamental] (calling these "fundamental types"), but the list isn't as convenient to navigate.
That would be a total of 20 primitive types (ignoring that char
and wchar_t
are treated separately from their explicitly signed
/unsigned
variants, because their default signedness is platform-dependent).
The standard also allows implementations to have "extended" signed and unsigned integer types. For instance, Clang supports a signed and unsigned __int128_t
, which would fall in that category, but it isn't required by the standard.
Upvotes: 2
Reputation: 1055
Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char , float, bool etc.
Primitive data types available in C++ are:
You think that the short int
and long int
are primitive data types.
Those are combined with primitive data type int
and data modifier short
and long
.
Datatype Modifiers: As the name implies, datatype modifiers are used with the built-in data types to modify the length of data that a particular data type can hold.
Data type modifiers available in C++ are:
This gives you the helpful answer.
Upvotes: 1
Reputation: 1208
It really depends on how you count the data types. This web site lists these 7:
bool
char
int
float
double
void
wchar_t
However, these types can be modified with signed
, unsigned
, short
, long
. The site that you mentioned lists all of these, plus the new ones like char16_t
and char32_t
. I think that the 28 listed is a very comprehensive list, and I can't think of any that have been omitted (they've even covered unsigned long long int
).
So, 28 looks right to me. The reason other sites my have different numbers is because they don't include the new ones, or they don't count all of the modifiers. Other sites may consider unsigned short int
different from short unsigned int
, but the two are equivalent.
Upvotes: 3