byte
short
int
long
The char
data type is designed for
Unicode characters.
Quotes are from The C Programming Language by Kernighan and Ritchie.
char
signed
or unsigined
char
may be either signed
or unsigined
int
short
or long
signed
or unsigined
int
is signed
Arithmetic with unsigned integers "obey the laws of arithmetic modulo 2n". Because signed integers are not required to be two's complement, many of their operations do not have a tight formal definition. For example, -5/2 could be either -2 or -3. If -5/2 is -2 then -5%2 must be -1, and if -5/2 is -3 then -5%2 must be 1; that is (-5/2)*2+5%2 must be 5.
The ANSI C standard requires that both the short int
and the plain int
be able to hold integers from
-32767 to 32767 when signed
and from
0 to 65535 when unsigned
.
The long int
must be able to hold integers from
-2147483647 to 2147483647 when signed
and from
0 to 4294967295 when unsigned
.
The C99 standard includes a long long
integer
which is required to hold at least 64 bits.
<limits.h>
: defines constants,
e.g., INT_MAX
for minimum and maximum values
#include <limits.h> #include <stdio.h> int main(void) { printf("Largest char is %d\n", SCHAR_MAX) ; printf("Largest short is %d\n", SHRT_MAX) ; printf("Largest int is %d\n", INT_MAX) ; printf("Largest long is %ld\n", LONG_MAX) ; return 0 ; }
Largest char is 127 Largest short is 32767 Largest int is 2147483647 Largest long is 2147483647
Largest char is 127 Largest short is 32767 Largest int is 2147483647 Largest long is 9223372036854775807
<stdint.h>
in C99 and most recent C compilers:
provides typedef
's
with size specific names, e.g., int32_t
and uint16_t
<pic24_generic.h>
of the textbook:
provides typedef
's
with size specific names, e.g., int32
and uint16