• 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

Please log in or register to answer this question.

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 11 views
0 votes
1 answer 10 views
10 views asked Oct 27, 2020 xgtx 320 points
0 votes
1 answer 14 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, 2020 adamSw 11.3k points
0 votes
1 answer 9 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 Oct 22, 2020 Code Learner 5.5k points
1 vote
1 answer 33 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, 2020 Gavin 15.3k points
0 votes
1 answer 7 views
How to convert string to char and how much slower it is to use std::string instead of char?
asked Dec 7, 2020 TeamScript 9.9k points
0 votes
1 answer 16 views
Convert string to char array in C++ I encountered the error 'cannot convert std::string to char[] or char* data type.' How can I solve it? Thanks!
asked Nov 15, 2020 miki 1.9k points
0 votes
1 answer 6 views
1 vote
1 answer 12 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, 2020 adamSw 11.3k points
1 vote
2 answers 75 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, 2020 Gavin 15.3k points