• Register
1 vote


I am just wondering if it is possible converting a char to int in C/C++. If possible, please help me by showing the way.


12 7 7
15,250 points

1 Answer

1 vote


Well, the answer is YES. You can convert a char to int type.  In ASCII code, the numbers (digits) start from 48.

char x = '4';
int ix = x - '0';

In this case, x-’0’ is identical as

((int)x) - ((int)'0')

that means the ASCII values of the characters are subtracted from each other. Hence, x is representing a number.

13 9 6
94,240 points

Related questions

0 votes
1 answer 13 views
Problem: Hello guys, I am a novice in computer programming. One of my friends is helping me to learn how to program. Well, I’ve chosen the c++ language as my friend suggested. I have got a question in my mind. If I declare a char value; could I change it to ... possible then how do I convert a char to int in C++? Please, explain all the things in simple words as I am a beginner. Thanks
asked Jun 24 adamSw 11.3k points
0 votes
1 answer 3 views
Problem: I want to convert a character to integer in C#. I have tried Convert.ToInt32(), int32.Parse(), (int)char, but nothing works as desired. I do not want to convert my character into string first. I want to convert my character directly into integer. How I can do that? Is there any mechanism for doing so?
asked 11 hours ago Sheeza 2.6k points
1 vote
1 answer 9 views
Problem: I need to cast only one char to string. The opposite way is pretty simple like str[0]. The following did not work for me: char c = 34; string(1,c); Do you guys have any idea how can I convert a character into a string? I would be grateful if you could solve the issue. I’ve already spent thirty minutes on this. Please, someone, come ahead and save my day. Thanks.
asked Jun 24 adamSw 11.3k points
1 vote
2 answers 60 views
Problem: Hello programmers, I am a newbie in computer programming. I started learning C plus plus programming a few days back. I enrolled in an online course and doing well so far. Today, I’ve completed the ‘Array’ chapter successfully. I’ve solved a few ... solutions in raw codes. To be honest, I have no idea about this problem and I can’t solve it as my own. Thanks
asked Apr 27 Gavin 15.3k points
1 vote
1 answer 27 views
Problem: I am new to c++ language, i dont know when i was printing character data by int it dint give the character instead it give me the number so my question is how can i convert it in char and display the output.If you know the solution please le me know.I am waiting for the response.
asked Jun 2 Gavin 15.3k points