You are not logged in. Please login at www.codechef.com to post your questions!

×

Regarding comparison of integer and character?

a is a character array which contains integers 0-9

   1) count=(count*10)+(a[i]-'0');

   2) if(a[i]>'9')
    {
        ch=a[i];
        printf("{Im executing:%c}",a[i]);
    }


1)what does the first mean, can a character be computed and subtracted as a normal integer variable or it is a kind of special case.
2)what does the second statement mean?.Does it mean integer is compared with an integer

-----------Help please-----------

This question is marked "community wiki".

asked 09 Dec '18, 21:31

harivenkyy's gravatar image

0★harivenkyy
11
accept rate: 0%

edited 09 Dec '18, 21:33


1) Here a[i] will be stored and used as its ASCII value. For example, '0' will have ASCII value of character '0', i.e. 48. Similarly, a[i] will be in range of 48-57. Hence, a[i]-'0' will be an integer value between 0-9.

2) Here a[i] is simply compared with a character '9'. Again, it will be compared with respect to their ASCII values. So, here a character is not compared to an integer. It is an ASCII value compared to another ASCII value. If you want to compare a[i] with integer value of '9', you can use a[i]>57.

link

answered 10 Dec '18, 23:31

m_never_dies's gravatar image

4★m_never_dies
234
accept rate: 0%

edited 10 Dec '18, 23:31

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×630
×34
×17

question asked: 09 Dec '18, 21:31

question was seen: 92 times

last updated: 10 Dec '18, 23:31