Char
A char can be define as follows:
#include <stdio.h>
int main() {
char test = 'a';
return 0;
}
Note: in here we have to use single quote '
A char can be increment by value like so:
#include <stdio.h>
int main() {
char test = 'a';
putchar(test++);
putchar(test++);
putchar(test++);
putchar(test++);
putchar(test++);
putchar(test++);
putchar(test++);
putchar(test++);
return 0;
}
abcdefgh
Compare to an int
Note that a char
can also be compared to an int
#include <stdio.h>
int main() {
printf("%d\n", 'a' - 91);
return 0;
}
6
Since a
is 97
when convert to int
.
This will also hold true
as well:
#include <stdio.h>
int main() {
printf("%d\n", 'a' == 97);
return 0;
}
1