The char type is the smallest numeric type, but is most commonly used to hold character values.
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|
| S | 2's Complement Magnitude | ||||||
#include <stdio.h>
#include <limits.h>
int main () {
char a; /* signed char by default */
signed char i; /* Explicit */
char signed x; /* Explicit */
a = 73;
i = 74;
x = 75;
printf ("a is %c (%d) (%d byte)\n", a, a, sizeof a);
printf ("i is %c (%d) (%d byte)\n", i, i, sizeof i);
printf ("x is %c (%d) (%d byte)\n", x, x, sizeof x);
a = -a;
i = -i;
x = -x;
printf ("a is %c (%d) (%d byte)\n", a, a, sizeof a);
printf ("i is %c (%d) (%d byte)\n", i, i, sizeof i);
printf ("x is %c (%d) (%d byte)\n", x, x, sizeof x);
printf ("The range of the char type is from %d to %d\n",
CHAR_MIN, CHAR_MAX);
printf ("The range of the signed char type is from %d to %d\n",
SCHAR_MIN, SCHAR_MAX);
return 0;
}