+ 2

Char array index output in C

When I tend to output the char array indices i.e char_array[0] and char_array[1] with the help of printf() function. You can see that code below. I use two type of format specifier (%c and %d) in printf() function for each char_array indices separately . Output comes from %c specifier gives a expected output But I won't understand the output comes from %d format specifier And I also confuse how does char_array index support %d format specifier https://code.sololearn.com/c1d6N74Zf0rm/?ref=app

1st Aug 2020, 2:18 PM
Yogeshwaran P
Yogeshwaran P - avatar
3 Answers
+ 4
Thank you Abhay ,Adnan Chowdhury and codemonkey. I ask these types of questions frequently because i am new to C programming Anyway thank you Friends :)
1st Aug 2020, 2:38 PM
Yogeshwaran P
Yogeshwaran P - avatar
+ 1
Yup that works as expected ,it actually print a character output for %c as you mentioned ,and ASCII value for that character using %d
1st Aug 2020, 2:21 PM
Abhay
Abhay - avatar
+ 1
Because the ASCII value of e=101 and h=104. When you print in decimal of e and h it prints the ASCII value of e and h.
1st Aug 2020, 2:22 PM
Adnan Chowdhury
Adnan Chowdhury - avatar