In C, the primitive types are referred to using a
combination of the keywords char, int, float, double, signed, unsigned, long, short and
void. The allowable combinations are
listed below, but their meanings depend on the compiler
and platform in use, unlike Java.
unsigned char-
The narrowest unsigned integral type, typically (and always at least) 8 bits wide
signed char-
The narrowest signed integral type, of the same width as
unsigned char char-
An integral type equivalent to one or other of the signed/unsigned variants, but its signedness is implementation-dependent — C treats it as a distinct type, though.
unsigned short-
An unsigned integral type at least as wide as
unsigned char, typically (and always at least) 16 bits short-
A signed integral type of the same width as
unsigned short unsigned-
An unsigned integral type at least as wide as
unsigned short, and wider than thechartypes — 16- or 32-bit widths are common. int-
A signed integral type of the same size as
unsigned unsigned long-
An unsigned integral type at least as wide as
unsigned, typically (and always at least) 32 bits long-
A signed integral type of the same size as
unsigned long unsigned long long-
In C99, an unsigned integral type at least as wide as
unsigned long, typically (and always at least) 64 bits long long-
In C99, a signed integral type of the same size as
unsigned long long float-
A single-precision floating-point type
double-
A double-precision floating-point type
long double-
An extended double-precision floating-point type
void-
An empty type — It has no values, and cannot be accessed. As in Java, C functions with no return value are defined to return
void. Unlike Java, a function with no parameters hasvoidin its parameter list.
In summary, C appears to have a lot of the same types
as Java, but this is not so, as you can't guarantee that
a C int
(for example) means the same as a Java int. Furthermore, C's signed types do
not have to use two's-complement notation, and Java does
not have unsigned types.
Note also that there is no boolean type. Instead, the
test conditions of if, while and for statements, and the
operands of the logical operators (!, && and
||), are integer expressions
with a boolean interpretation: zero means false, non-zero
means true. The relational operators (==, !=,
<=, >=, <
and >) and logical
operators return 0 for false
and 1 for true.
In C99, there is a
boolean type bool (which is really
just a very small integer type) and symbolic values
true and false (i.e. just 1 and 0), but the other integer
types work just as well as before.