I am reading Programming in C by Stephan G. Kochan
. He states that C has only five data types; int
, float
, double
, char
and _Bool
.
What about long
? Isn't it a builtin type? http://www.programiz.com/c-programming/c-data-types says long
is a qualifier to modify the size. If it is a qualifier then it should be only used as a long int
, and not as a standalone long
.
And what about _Bool
? Many Internet tutorials say there is no boolean type in C.
Related:
Is long long a type in C?
Is "long long" = "long long int" = "long int long" = "int long long"?
In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer.
“short” is the qualifier and “int” is the basic datatype. If you are interested in learning Programming Languages that will enhance your job opportunities, then check out the Programming classes from Intellipaat.
He states that C has only five data types; int, float, double, char and _Bool.
That's quite an over-simplification. Maybe intentional, if the book is aimed towards beginners.
If you go through C11 6.2.5 it lists the following distinct data types:
Character types (6.2.5/15)
char signed char unsigned char
Standard signed integer types (6.2.5/4)
signed char short int int long int long long int
Standard unsigned integer types (6.2.5/5)
_Bool unsigned char unsigned short int unsigned int unsigned long int unsigned long long int
Real floating types (6.2.5/10)
float double long double
Complex types (6.2.5/11)
float _Complex double _Complex long double _Complex
Enumerated type (6.2.5/16)
enum {}
void type (6.2.5/19) (void type is an incomplete type)
void
Derived types (6.2.5/20)
Formally the term is type specifier 6.7.2:
type-specifier: void char short int long float double signed unsigned _Bool _Complex atomic-type-specifier struct-or-union-specifier enum-specifier typedef-name
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
— void
— char
— signed char
— unsigned char
— short, signed short, short int, or signed short int
— unsigned short, or unsigned short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
— unsigned long, or unsigned long int
— long long, signed long long, long long int, or signed long long int
— unsigned long long, or unsigned long long int
— float
— double
— long double
— _Bool
— float _Complex
— double _Complex
— long double _Complex
— atomic type specifier
— struct or union specifier
— enum specifier
— typedef name
As we can see, long
is a type specifier. It is not a type qualifier.
From the C11 draft, section 6.2.5 ("Types)" paragraph 4:
There are five standard signed integer types, designated as
signed char
,short int
,int
,long int
, andlong long int
.
How these types are specified in program text is another issue, there are many ways since the syntax is rather lax. For instance, according to 6.7.2 ("Type Specifiers") the following are all valid ways to specify the same type:
long
,signed long
,long int
, orsigned long int
This says that long
by itself is a valid type specifier for the type long int
. This was the same in C99 (and, I would guess, earlier standards too). So no, it's not a qualifier.
In addition, the above can be intermixed with things like static
, volatile
, pointer asterisks, and so on.
I would suggest reading some other book, since it's confusing to read books that use different terminology from the standard. The standard is often refered to when answering questions about C, so it's a good idea to be familiar with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With