Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the meaning of this expression

I am trying to push a integer that is stored in a string to a stack of type int I was trying to do the same by using stack.push(str[i]) which resulted in some weird values in the final outcome

Github copilot suggeted to do it this way which was succesfull

else
       {
           temp.push(exp[i]-'0');
       }

what is the meaning of -‘0’ here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The char ‘0’ has ascii value 0x30 (48 decimal).

The char ‘9’ has ascii value 0x39 (57 decimal).

If you do '9' - '0' = 57 - 48 = 9.

So you are converting a digit from its ascii number '9' = 57 to its numeric value 9.

This is often used when fast-converting a string of integers to its numeric value.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading