C++ Data Types – Understanding ‘long long’ Syntax vs ‘int int’

cdata types

I was wondering if long long specifies a single datatype then why don't things like int int work? I meant obviously that's not a data type but there is a long data type. Essentially what I'm asking is:

int a = 0; //okay
long b = 0; //still fine
long long c = 0; //really long number but its okay....
int int d = 0; //error

why?

Best Answer

The difference between long long and int int is that long modifies a type, rather than being a type itself. long is really a shorthand for long int and long long a shorthand for long long int.

More specifically int is a type specifier, just like char or bool. long is a type modifier. Other type modifiers are unsigned and signed and short.

If one of the modifiers is missing then the type will fall back to a default. E.g. if there is no signed or unsigned then the type will be signed. If there is no short or long the default size depends on the compiler and the architecture.

Take a look at this table on Wikipedia for a full list of how different type specifiers and modifiers can be combined.

Edit:

In current versions of the C and C++ standards long and short are actually type specifiers in their own right. This doesn't change the way that things can be combined though.

Related Topic