0

Converting character digit into int type

How do i convert a character say char a[2] = "11" into integer type? (char a[2] ="11" - - - > int i =11)

29th Jul 2017, 11:44 AM
Rishubh Naik
Rishubh Naik - avatar
4 Answers
+ 11
(int) a[2]
29th Jul 2017, 11:47 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 8
I don't think it's going to work the way you want it to. Casting an int value to char, and converting int values to their char counterparts is different. You may be looking for something like this: https://code.sololearn.com/czOgq2u6N5fc/?ref=app
29th Jul 2017, 11:56 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
You mean to say, int i = (int) a[2]?
29th Jul 2017, 11:49 AM
Rishubh Naik
Rishubh Naik - avatar
+ 1
@ValentinHacker That will not work in C++. When you cast an ASCII character to int, you will get the ascii code that represents that character, not the actual number
29th Jul 2017, 4:41 PM
aklex
aklex - avatar