• Register
1 vote
23 views

Problem:

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.

Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

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

1 vote
1 answer 8 views
8 views
Problem: So again I am facinhg this problem. Convert char array to int c++.
asked Mar 25 PkGuy 13.1k points
0 votes
1 answer 12 views
12 views
Problem Anyone can help me?How to convert int to char in c++
asked Mar 23 Subhendu 4.5k points
0 votes
1 answer 14 views
14 views
Problem: here is we are going to discuss the problem how to convert “int” into “char”
asked Feb 15 jasimchaudary 1.5k points
0 votes
1 answer 21 views
21 views asked Jan 27 Afi khan 1.4k points
0 votes
1 answer 17 views
0 votes
1 answer 15 views
15 views asked Oct 27, 2020 xgtx 320 points
0 votes
1 answer 17 views
17 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 12 views
12 views asked Jan 24 Akhil k 1.3k points
0 votes
1 answer 4 views
4 views
Problem: I am looking for some assistance on "How to convert char array to int array in java? "
asked Apr 1 zayed1 35.6k points
0 votes
1 answer 25 views
25 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 9.2k points