[Solved] How is the value character converted into integer?


How is an integer converted into character?

Let us look at "%d" first.

printf("\nThe 4th output is %d", a);

a has the value of 97 at this point. As printf() sees a "%d", it expects to see an int as the next argument – which it is – good. The value of 97 causes 2 characters to print: '9' and '7'.

fprintf c
The int argument is converted to signed decimal in the style [−]dddd..
C11dr §7.21.6.1 8


Now "%c".

printf("\nThe 1st outpit is: %c", a);

a has the value of 97 at this point. As printf() sees a "%c", it expects to see an int as the next argument – which it is – good. Then the int value is converted to unsigned char, which is still value 97. Then the character corresponding to 97 is “printed”. This correspondence is overwhelming though ASCII for the values 0-127 and so a character ‘a’ is seen.

…, the int argument is converted to an unsigned char, and the resulting character is written.

solved How is the value character converted into integer?