Conversion of char to int
Hey guys,
I have been solving a problem post-fix expression evaluation using stacks for lab in the weekend and encountered a problem "conversion of character data to int". I searched through google and found these results "atoi and typecasting".
Both the above conversions are known to me but I came across something different like this
char i='5';
int j = i-'0';
in 'j' the integer value number:5 is stored can anyone please explain how its working
I have been solving a problem post-fix expression evaluation using stacks for lab in the weekend and encountered a problem "conversion of character data to int". I searched through google and found these results "atoi and typecasting".
Both the above conversions are known to me but I came across something different like this
char i='5';
int j = i-'0';
in 'j' the integer value number:5 is stored can anyone please explain how its working
Replies
-
Manish Goyali think here intenal type casting is going on
when you write int j=i-'0', compiler takea ascii value of '5' i.e 53 and '0' which is 48 , -
hari02Ya..................Thanx Goyal 😁
-
HirenBarbhaya
Awesome Explanation...goyal420i think here intenal type casting is going on
when you write int j=i-'0', compiler takea ascii value of '5' i.e 53 and '0' which is 48 , -
rohitrkvariable i stores the acii value of '5'. when statement j=i-'0' is executed the char '5' is converted to number 5.
this is one of the ways we use to convert a number from its ascii value to integer value so that arithmetic operations can be performed on it.
You are reading an archived discussion.
Related Posts
Here's a collection software manual testing interview questions and answers, most commonly asked in interviews.
1. Tell us about yourself? (This is to know the person and assess the communication...
I have a lenovo g560 & trying to connect to the projector. But it is not connected to projector and it display on blank screen. please any body give me...
hey Friends😀
Does anyone have the avira license key!:sshhh:
I am using SQLite for my application. when I used truncate command in SQLite it gives me error like " syntax Error near truncate".
Can anyone help me to solve...
Wishing you a very-2 happy birthday 4M4N from Crazy Engineers 😀
🎉:myparty:🎉