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

Replies

  • Manish Goyal
    Manish Goyal
    i 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 ,
  • hari02
    hari02
    Ya..................Thanx Goyal 😁
  • HirenBarbhaya
    HirenBarbhaya
    goyal420
    i 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 ,
    Awesome Explanation...
  • rohitrk
    rohitrk
    variable 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:🎉