CrazyEngineers
  • hari02
    hari02

    MemberFeb 14, 2011

    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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberFeb 14, 2011

    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 ,
    Are you sure? This action cannot be undone.
    Cancel
  • hari02

    MemberFeb 14, 2011

    Ya..................Thanx Goyal 😁
    Are you sure? This action cannot be undone.
    Cancel
  • HirenBarbhaya

    MemberFeb 17, 2011

    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...
    Are you sure? This action cannot be undone.
    Cancel
  • rohitrk

    MemberFeb 17, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register