C examples for Language Basics:Variable
The char type represents ASCII characters.
The character constants are enclosed in single quotes.
#include <stdio.h> int main() {/*from w w w . j a v a 2 s .co m*/ char c = 'x'; /* assigns 120 (ASCII for x) */ }
You can use the %c format specifier to print out the ASCII character.
#include <stdio.h> int main() {/*from ww w .ja v a2s. co m*/ char c = 'x'; /* assigns 120 (ASCII for x) */ printf("%c", c); /* "x" */ }
Use the %d specifier to instead display the numerical value.
#include <stdio.h> int main() {//from w w w. j av a2s . c o m char c = 'x'; /* assigns 120 (ASCII for x) */ printf("%d", c); /* "120" */ }