In C/C++, characters are stored internally as binary. On ASCII system, they are stored as ASCII value. Thus, you can do:
Code:
char ch = 'A';
or
Code:
char ch = 65;
or
Code:
char ch = 0x41;
They are all equivalent.
Therefore, taking any value, say 65. You can treat it like any integer value, or ASCII representation of character ¡¥A¡¦. Internally, the program always uses numeric 65. The only time you need to differentiate 65 or 0x41 or ¡¥A¡¦ is when you output the value in some human readable context. In this case, you can use the printf() format specification to ¡¥translate¡¦ how the data needs to be presented.
To output decimal 65:
Code:
printf("%d", ch);
[\code]
To output hex 0x41:
[code]
printf("0x%X", ch);
[\code]
To output character ¡¥A¡¦:
[code]
printf("'%c'", ch);
[\code]
Hope this answer your question.
Shyan
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.