Printing char by integer qualifier

c, c++

Solution

A characters that begins with `\0` represents Octal number, is the base-8 number system, and uses the digits `0 to 7`. So `\08` is invalid representation of octal number because 8 ∉ [0, 7], hence you're getting implementation-defined behavior.

Probably your compiler recognize a Multibyte Character `'\08'` as `'\0'` one character and `'8'` as another and interprets as `'\08'` as `'\0'` + `'8'` which makes it `'8'`. After looking at the ASCII table, you'll note that the decimal value of `'8'` is 56.

Thanks to @DarkDust, @GrijeshChauhan and @EricPostpischil.

Problem

I am trying to execute the below program. ``` #‎include‬ "stdio.h" #include "string.h" void main() { char c='\08'; printf("%d",c); } ``` I'm getting the output as `56` . But for any numbers other than `8` , the output is the number itself , but for `8` the answer is `56`. Can somebody explain ?

Original source

Related problems